#include <bits/stdc++.h> using namespace std; using ll = long long; #define FOR(i,a,b) for(ll i=a; i<=b; ++i) #define FORR(i,a,b) for(ll i=a; i>=b; --i) #define pb push_back constexpr int MAX_N=1e9+14; ll H, W, N, rres=0; vector<int> pict; void Input(){ int a; cin>>H>>W>>N; FOR(i,0,N-1) cin>>a, pict.pb(a); } void Solve(){ if(W%pict[0]!=0||H%pict[0]!=0){cout<<"-1\n"; return;} ll delW=0, delH=0, cE; FORR(i,N-1,0){ cE=pict[i]; rres+=(((W-delW)/cE)*(H/cE))+((W/cE)*((H-delH)/cE))-(((W-delW)/cE)*((H-delH)/cE)); delW+=((W-delW)/cE)*cE, delH+=((H-delH)/cE)*cE; } cout<<rres<<"\n"; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); Input(); Solve(); }
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 <bits/stdc++.h> using namespace std; using ll = long long; #define FOR(i,a,b) for(ll i=a; i<=b; ++i) #define FORR(i,a,b) for(ll i=a; i>=b; --i) #define pb push_back constexpr int MAX_N=1e9+14; ll H, W, N, rres=0; vector<int> pict; void Input(){ int a; cin>>H>>W>>N; FOR(i,0,N-1) cin>>a, pict.pb(a); } void Solve(){ if(W%pict[0]!=0||H%pict[0]!=0){cout<<"-1\n"; return;} ll delW=0, delH=0, cE; FORR(i,N-1,0){ cE=pict[i]; rres+=(((W-delW)/cE)*(H/cE))+((W/cE)*((H-delH)/cE))-(((W-delW)/cE)*((H-delH)/cE)); delW+=((W-delW)/cE)*cE, delH+=((H-delH)/cE)*cE; } cout<<rres<<"\n"; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); Input(); Solve(); } |