#include<bits/stdc++.h>
using namespace std;
#ifdef DEBUG
auto&operator <<(auto& o, pair<auto, auto> p) {return o<<"("<<p.first<<", "<<p.second<<")";}
auto operator <<(auto& o, auto x)->decltype(x.end(), o) {o<<"{"; for(auto v : x) o<<v<<", "; return o<<"}";}
#define debug(X) cout<<"["#X"]"<<X<<endl;
#else
#define debug(X) {}
#endif
#define int long long
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int h, w;
cin>>h>>w;
int mm = h*w;
int n;
cin>>n;
int result = 0;
int pop;
cin>>pop;
if(h%pop != 0 || w%pop != 0) {cout<<-1; return 0;}
for(int i=1;i<n;i++)
{
int d;
cin>>d;
result += ((h%d)*w + (w%d)*h - (h%d)*(w%d))/(pop*pop);
pop = d;
h -= h%d;
w -= w%d;
}
result += (w*h)/(pop*pop);
cout<<result;
}
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> using namespace std; #ifdef DEBUG auto&operator <<(auto& o, pair<auto, auto> p) {return o<<"("<<p.first<<", "<<p.second<<")";} auto operator <<(auto& o, auto x)->decltype(x.end(), o) {o<<"{"; for(auto v : x) o<<v<<", "; return o<<"}";} #define debug(X) cout<<"["#X"]"<<X<<endl; #else #define debug(X) {} #endif #define int long long int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int h, w; cin>>h>>w; int mm = h*w; int n; cin>>n; int result = 0; int pop; cin>>pop; if(h%pop != 0 || w%pop != 0) {cout<<-1; return 0;} for(int i=1;i<n;i++) { int d; cin>>d; result += ((h%d)*w + (w%d)*h - (h%d)*(w%d))/(pop*pop); pop = d; h -= h%d; w -= w%d; } result += (w*h)/(pop*pop); cout<<result; } |
English