#include <bits/stdc++.h> using namespace std; int64_t Count(int64_t h, int64_t w, int64_t dh, int64_t dw) { return h * w - (h - dh) * (w - dw); } int main() { int h, w, n; vector<int> d; scanf("%d%d%d", &h, &w, &n); d.resize(n); for (int i = 0; i < n; i++) scanf("%d", &d[i]); int64_t count = 0; if (h % d[0] != 0 || w % d[0] != 0) { printf("-1\n"); return 0; } for (int i = 0; i < n - 1; i++) { int rh = h % d[i + 1]; int rw = w % d[i + 1]; count += Count(h / d[i], w / d[i], rh / d[i], rw / d[i]); h -= rh; w -= rw; } count += int64_t(h / d.back()) * (w / d.back()); printf("%ld\n", count); 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 | #include <bits/stdc++.h> using namespace std; int64_t Count(int64_t h, int64_t w, int64_t dh, int64_t dw) { return h * w - (h - dh) * (w - dw); } int main() { int h, w, n; vector<int> d; scanf("%d%d%d", &h, &w, &n); d.resize(n); for (int i = 0; i < n; i++) scanf("%d", &d[i]); int64_t count = 0; if (h % d[0] != 0 || w % d[0] != 0) { printf("-1\n"); return 0; } for (int i = 0; i < n - 1; i++) { int rh = h % d[i + 1]; int rw = w % d[i + 1]; count += Count(h / d[i], w / d[i], rh / d[i], rw / d[i]); h -= rh; w -= rw; } count += int64_t(h / d.back()) * (w / d.back()); printf("%ld\n", count); return 0; } |