#include<bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll w,h; cin>>w>>h; ll n; cin>>n; vector <ll> v(n); for(ll i=0;i<n;i++) { cin>>v[i]; } if(w%v[0]!=0||h%v[0]!=0) { cout<<"-1"<<"\n"; } else { ll res=(w*h)/(v[0]*v[0]); for(int i=1;i<n;i++) { ll a=w/v[i]*v[i]; ll b=h/v[i]*v[i]; if(a!=0&&b!=0) { res-=(a*b)/(v[i-1]*v[i-1]); res+=(a*b)/(v[i]*v[i]); } } cout<<res<<"\n"; } 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 | #include<bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll w,h; cin>>w>>h; ll n; cin>>n; vector <ll> v(n); for(ll i=0;i<n;i++) { cin>>v[i]; } if(w%v[0]!=0||h%v[0]!=0) { cout<<"-1"<<"\n"; } else { ll res=(w*h)/(v[0]*v[0]); for(int i=1;i<n;i++) { ll a=w/v[i]*v[i]; ll b=h/v[i]*v[i]; if(a!=0&&b!=0) { res-=(a*b)/(v[i-1]*v[i-1]); res+=(a*b)/(v[i]*v[i]); } } cout<<res<<"\n"; } return 0; } |