#include <bits/stdc++.h>
using namespace std;
const int MAXN=3e5+5;
long long d[31];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
long long pole=0, h, w, n, it1=0, it2=0, ans=0, h1, w1;
cin >>h >>w;
if(h>w) swap(h, w);
cin >>n;
for(int i=1; i<=n; i++) cin >>d[i];
if(h%d[1]!=0 || w%d[1]!=0)
{
cout <<-1;
return 0;
}
for(int i=n; i>0; i--)
{
ans+=h/d[i]*(w/d[i]);
//cout <<ans <<" ";
ans-=it1/d[i]*(it2/d[i]);
//cout <<ans <<"\n";
it1=h/d[i]*d[i];
it2=w/d[i]*d[i];
}
/*for(int i=n; i>0; i--)
{
int temp=(h-it1)/d[i];
cout <<d[i] <<" " <<temp <<" " <<it1 <<"\n";
if(it2==0) it2=w/d[i]*d[i];
ans+=temp*it2/d[i];
cout <<ans <<"\n";
it1+=temp*d[i];
}
if(it1!=h)
{
cout <<-1;
return 0;
}
cout <<ans <<"\n";
for(int i=n; i>0; i--)
{
int temp=(w-it2)/d[i];
cout <<d[i] <<" " <<temp <<" " <<it2 <<"\n";
ans+=temp*h/d[i];
it2+=temp*d[i];
}
if(it2!=w)
{
cout <<-1;
return 0;
}*/
cout <<ans;
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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | #include <bits/stdc++.h> using namespace std; const int MAXN=3e5+5; long long d[31]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long pole=0, h, w, n, it1=0, it2=0, ans=0, h1, w1; cin >>h >>w; if(h>w) swap(h, w); cin >>n; for(int i=1; i<=n; i++) cin >>d[i]; if(h%d[1]!=0 || w%d[1]!=0) { cout <<-1; return 0; } for(int i=n; i>0; i--) { ans+=h/d[i]*(w/d[i]); //cout <<ans <<" "; ans-=it1/d[i]*(it2/d[i]); //cout <<ans <<"\n"; it1=h/d[i]*d[i]; it2=w/d[i]*d[i]; } /*for(int i=n; i>0; i--) { int temp=(h-it1)/d[i]; cout <<d[i] <<" " <<temp <<" " <<it1 <<"\n"; if(it2==0) it2=w/d[i]*d[i]; ans+=temp*it2/d[i]; cout <<ans <<"\n"; it1+=temp*d[i]; } if(it1!=h) { cout <<-1; return 0; } cout <<ans <<"\n"; for(int i=n; i>0; i--) { int temp=(w-it2)/d[i]; cout <<d[i] <<" " <<temp <<" " <<it2 <<"\n"; ans+=temp*h/d[i]; it2+=temp*d[i]; } if(it2!=w) { cout <<-1; return 0; }*/ cout <<ans; return 0; } |
English