#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using llu = unsigned long long;
#define int ll
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
llu h, w;
cin >> h >> w;
llu n;
cin >> n;
vector<llu> d(n);
for (llu i = 0; i < n; i++) {
cin >> d[i];
}
if (h % d[0] || w % d[0]) {
cout << "-1\n";
return 0;
}
llu ans = h / d[0] * (w / d[0]);
h /= d[0];
w /= d[0];
for (llu i = 1; i < n; i++) {
llu x = d[i] / d[i-1];
h /= x;
w /= x;
ans -= h * w * x * x;
ans += h * w;
}
cout << ans << '\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 | #include <bits/stdc++.h> using namespace std; using ll = long long; using llu = unsigned long long; #define int ll int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); llu h, w; cin >> h >> w; llu n; cin >> n; vector<llu> d(n); for (llu i = 0; i < n; i++) { cin >> d[i]; } if (h % d[0] || w % d[0]) { cout << "-1\n"; return 0; } llu ans = h / d[0] * (w / d[0]); h /= d[0]; w /= d[0]; for (llu i = 1; i < n; i++) { llu x = d[i] / d[i-1]; h /= x; w /= x; ans -= h * w * x * x; ans += h * w; } cout << ans << '\n'; } |
English