#include <bits/stdc++.h>
#define ll long long 
using namespace std;
vector <ll> t;
ll w,h,res=0;
void f(ll x, ll &w, ll &h, ll i){
    int w1=w,h1=h;
    w/=x; w*=x;
    h/=x; h*=x;
    res+=((w1*h1)-(w*h))/(t[i-1]*t[i-1]);
    
    
    //cout<<res<<" "<<w<<" "<<h<<" "<<w1<<" "<<h1<<" "<<t[i-1]<<endl;
}
int main()
{
    int n; 
    cin>>w>>h>>n;
    for(int i=1; i<=n; i++){
        int x; cin>>x; t.push_back(x);
    }
    sort(t.begin(),t.end());
    if(w%t[0]!=0 || h%t[0]!=0){
        cout<<"-1";
        return 0;
    }
    ll *ith=&h;
    ll *itw=&w;
    for(int i=1; i<n; i++)
        f(t[i],w,h,i);
    
    res+=w*h/(t[n-1]*t[n-1]);
    cout<<res<<endl;
    return 0;
}
        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 35 36  | #include <bits/stdc++.h> #define ll long long using namespace std; vector <ll> t; ll w,h,res=0; void f(ll x, ll &w, ll &h, ll i){ int w1=w,h1=h; w/=x; w*=x; h/=x; h*=x; res+=((w1*h1)-(w*h))/(t[i-1]*t[i-1]); //cout<<res<<" "<<w<<" "<<h<<" "<<w1<<" "<<h1<<" "<<t[i-1]<<endl; } int main() { int n; cin>>w>>h>>n; for(int i=1; i<=n; i++){ int x; cin>>x; t.push_back(x); } sort(t.begin(),t.end()); if(w%t[0]!=0 || h%t[0]!=0){ cout<<"-1"; return 0; } ll *ith=&h; ll *itw=&w; for(int i=1; i<n; i++) f(t[i],w,h,i); res+=w*h/(t[n-1]*t[n-1]); cout<<res<<endl; return 0; }  | 
            
        
                    English