#include<bits/stdc++.h>
using namespace std;
void solve() {
long long h, w; cin >> h >> w;
long long n; cin >> n;
vector<long long> t(n);
for(int i = 0; i < n; i++) {
cin >> t[i];
}
if(h % t[0] != 0 || w % t[0] != 0) {
cout << -1 << "\n";
return;
}
reverse(t.begin(), t.end());
long long ans = 0LL;
long long area = 0LL;
for(int i = 0; i < n; i++) {
long long new_area = (h - (h % t[i])) * (w - (w % t[i])) - area;
ans += new_area / (t[i] * t[i]);
area += new_area;
}
cout << ans << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
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 | #include<bits/stdc++.h> using namespace std; void solve() { long long h, w; cin >> h >> w; long long n; cin >> n; vector<long long> t(n); for(int i = 0; i < n; i++) { cin >> t[i]; } if(h % t[0] != 0 || w % t[0] != 0) { cout << -1 << "\n"; return; } reverse(t.begin(), t.end()); long long ans = 0LL; long long area = 0LL; for(int i = 0; i < n; i++) { long long new_area = (h - (h % t[i])) * (w - (w % t[i])) - area; ans += new_area / (t[i] * t[i]); area += new_area; } cout << ans << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); return 0; } |
English