#include <iostream>
#include <fstream>
using namespace std;
#define ll long long
int n;
int d[40];
int h;
int w;
ll odp(){
if((h%d[0]) || (w%d[0])) return -1;
ll s[40];
int b[40];
for(int i=0; i<n; i++){
s[i]=h/d[i];
s[i]*=w/d[i];
s[i]*=d[i];
s[i]*=d[i];
}
s[n]=0;
for(int i=0; i<n; i++){
s[i]-=s[i+1];
//cout << s[i] << endl;
}
ll zwrot=0;
for(int i=0; i<n; i++){
s[i]/=d[i];
s[i]/=d[i];
zwrot+=s[i];
}
return zwrot;
}
int main()
{
scanf("%d %d", &h, &w);
scanf("%d", &n);
for(int i=0; i<n; i++)
scanf("%d", d+i);
cout << odp();
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 | #include <iostream> #include <fstream> using namespace std; #define ll long long int n; int d[40]; int h; int w; ll odp(){ if((h%d[0]) || (w%d[0])) return -1; ll s[40]; int b[40]; for(int i=0; i<n; i++){ s[i]=h/d[i]; s[i]*=w/d[i]; s[i]*=d[i]; s[i]*=d[i]; } s[n]=0; for(int i=0; i<n; i++){ s[i]-=s[i+1]; //cout << s[i] << endl; } ll zwrot=0; for(int i=0; i<n; i++){ s[i]/=d[i]; s[i]/=d[i]; zwrot+=s[i]; } return zwrot; } int main() { scanf("%d %d", &h, &w); scanf("%d", &n); for(int i=0; i<n; i++) scanf("%d", d+i); cout << odp(); return 0; } |
English