#include <bits/stdc++.h>
using namespace std;
long long h, w;
int n;
long long obr[30];
long long int res;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> h >> w;
cin >> n;
for(int i = 0; i < n; i++){
cin >> obr[i];
}
if(h % obr[0] != 0 || w % obr[0] != 0){
cout << -1 << "\n";
return 0;
}
if(h > w) swap(h, w);
for(int i = 0; i < n -1; i++){
long long x = h % obr[i+1];
long long rem = x;
x /= obr[i];
long long y = w / obr[i];
res += x * y;
h -= rem;
x = w % obr[i+1];
rem = x;
x /= obr[i];
y = h / obr[i];
res += x * y;
w -= rem;
}
res += (h / obr[n-1]) * (w / obr[n-1]);
cout << res << "\n";
}
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 | #include <bits/stdc++.h> using namespace std; long long h, w; int n; long long obr[30]; long long int res; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cin >> h >> w; cin >> n; for(int i = 0; i < n; i++){ cin >> obr[i]; } if(h % obr[0] != 0 || w % obr[0] != 0){ cout << -1 << "\n"; return 0; } if(h > w) swap(h, w); for(int i = 0; i < n -1; i++){ long long x = h % obr[i+1]; long long rem = x; x /= obr[i]; long long y = w / obr[i]; res += x * y; h -= rem; x = w % obr[i+1]; rem = x; x /= obr[i]; y = h / obr[i]; res += x * y; w -= rem; } res += (h / obr[n-1]) * (w / obr[n-1]); cout << res << "\n"; } |
English