#include <iostream> int main() { int64_t h, w, n; std::cin >> h >> w >> n; int64_t last; std::cin >> last; if (h % last != 0 || w % last != 0) { std::cout << "-1\n"; } else { h /= last; w /= last; int64_t ret = 0; for (int i = 1; i < n; ++i) { int64_t next; std::cin >> next; int64_t div = next / last; last = next; ret += (h % div) * w + (w % div) * h - (h % div) * (w % div); h /= div; w /= div; } ret += h * w; std::cout << ret << "\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 | #include <iostream> int main() { int64_t h, w, n; std::cin >> h >> w >> n; int64_t last; std::cin >> last; if (h % last != 0 || w % last != 0) { std::cout << "-1\n"; } else { h /= last; w /= last; int64_t ret = 0; for (int i = 1; i < n; ++i) { int64_t next; std::cin >> next; int64_t div = next / last; last = next; ret += (h % div) * w + (w % div) * h - (h % div) * (w % div); h /= div; w /= div; } ret += h * w; std::cout << ret << "\n"; } } |