#include <bits/stdc++.h> #define pb push_back #define ull unsigned long long using namespace std; ull n,w,h,z; ull wyn, s,a,b; vector <ull> v; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>h>>w>>n; for (int i=0; i<n; i++){ cin>>z; v.pb(z); } if (h%v[0]!=0 || w%v[0]!=0){ cout<<"-1"; return 0; } wyn=(h/v[0])*(w/v[0]); for (int i=1; i<v.size(); i++){ s=(v[i]*v[i])/(v[i-1]*v[i-1]); a=w/v[i]; b=h/v[i]; wyn-=((s-1)*(a*b)); } cout<<wyn; 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 | #include <bits/stdc++.h> #define pb push_back #define ull unsigned long long using namespace std; ull n,w,h,z; ull wyn, s,a,b; vector <ull> v; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>h>>w>>n; for (int i=0; i<n; i++){ cin>>z; v.pb(z); } if (h%v[0]!=0 || w%v[0]!=0){ cout<<"-1"; return 0; } wyn=(h/v[0])*(w/v[0]); for (int i=1; i<v.size(); i++){ s=(v[i]*v[i])/(v[i-1]*v[i-1]); a=w/v[i]; b=h/v[i]; wyn-=((s-1)*(a*b)); } cout<<wyn; return 0; } |