#include <iostream> #include <string> #include <algorithm> #include <vector> #define LL long long using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); LL w, h; cin >> w >> h; int n; cin >> n; vector<LL> d(n); for (int i = 0; i < n; ++i) cin >> d[i]; for (int i = n - 1; i; --i) d[i] /= d[i - 1]; LL res = 0ll; for (int i = 0; i < n; ++i) { res += (w % d[i]) * h + (h % d[i]) * w - (w % d[i]) * (h % d[i]); w /= d[i]; h /= d[i]; if (!i && res) { cout << "-1"; return 0; } } res += w * h; cout << res; }
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 | #include <iostream> #include <string> #include <algorithm> #include <vector> #define LL long long using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); LL w, h; cin >> w >> h; int n; cin >> n; vector<LL> d(n); for (int i = 0; i < n; ++i) cin >> d[i]; for (int i = n - 1; i; --i) d[i] /= d[i - 1]; LL res = 0ll; for (int i = 0; i < n; ++i) { res += (w % d[i]) * h + (h % d[i]) * w - (w % d[i]) * (h % d[i]); w /= d[i]; h /= d[i]; if (!i && res) { cout << "-1"; return 0; } } res += w * h; cout << res; } |