#include<bits/stdc++.h> using namespace std; long long n, h, w, wyn, s,a,b, c, d, e, f; vector<int> v; int main(){ cin>>h>>w>>n; for(int i=0; i<n; i++){ cin>>a; v.push_back(a); } sort(v.begin(), v.end()); 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){ c=(v[i-1]); d=(v[i]); s=(d*d)/(c*c); //cout<<s<<endl; e=(h/v[i]); f=(w/v[i]); wyn-=((e*f)*(s-1)); } cout<<wyn; }
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 | #include<bits/stdc++.h> using namespace std; long long n, h, w, wyn, s,a,b, c, d, e, f; vector<int> v; int main(){ cin>>h>>w>>n; for(int i=0; i<n; i++){ cin>>a; v.push_back(a); } sort(v.begin(), v.end()); 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){ c=(v[i-1]); d=(v[i]); s=(d*d)/(c*c); //cout<<s<<endl; e=(h/v[i]); f=(w/v[i]); wyn-=((e*f)*(s-1)); } cout<<wyn; } |