#include <iostream>
#include <vector>
std::vector<long long> t;
long long solve (long long h, long long w){
    if (h==0 or w==0)return 0;
    if (h<w)std::swap(h,w);
    //h>=w
    int my_size;
    for (int i=0; i<t.size(); ++i){
        if (t[i]<=w)my_size=t[i];
    }
    long long r1=h%my_size, r2=w%my_size;
    return (h/my_size)*(w/my_size)+solve(r1,w)+solve(r2,h-r1);
}
int main(){
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0);
    int h, w;
    std::cin>>h>>w;
    int n;
    std::cin>>n;
    for (int i=0; i<n; ++i){
        int a;
        std::cin>>a;
        t.push_back(a);
    }
    if (h%t[0]!=0 or w%t[0]!=0){
        std::cout<<-1<<'\n';
        return 0;
    }
    std::cout<<solve(h,w)<<'\n';
}
        1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34  | #include <iostream> #include <vector> std::vector<long long> t; long long solve (long long h, long long w){ if (h==0 or w==0)return 0; if (h<w)std::swap(h,w); //h>=w int my_size; for (int i=0; i<t.size(); ++i){ if (t[i]<=w)my_size=t[i]; } long long r1=h%my_size, r2=w%my_size; return (h/my_size)*(w/my_size)+solve(r1,w)+solve(r2,h-r1); } int main(){ std::ios_base::sync_with_stdio(false); std::cin.tie(0); int h, w; std::cin>>h>>w; int n; std::cin>>n; for (int i=0; i<n; ++i){ int a; std::cin>>a; t.push_back(a); } if (h%t[0]!=0 or w%t[0]!=0){ std::cout<<-1<<'\n'; return 0; } std::cout<<solve(h,w)<<'\n'; }  | 
            
        
                    English