#include <algorithm> #include <iostream> #include <limits> #include <vector> using namespace std; #define ull unsigned long long #define ULL_MAX std::numeric_limits<ull>::max() int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ull h, w; cin >> h >> w; int n; cin >> n; ull d; ull res; cin >> d; if (w % d != 0 || h % d != 0) { cout << -1; return 0; } res = (w / d) * (h / d); w /= d; h /= d; for (int i = 1; i < n; i++) { int prevD = d; cin >> d; int artD = d / prevD; res -= (w / artD) * (h / artD) * (artD * artD - 1); w /= artD; h /= artD; } cout << res; 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 35 36 37 38 39 40 | #include <algorithm> #include <iostream> #include <limits> #include <vector> using namespace std; #define ull unsigned long long #define ULL_MAX std::numeric_limits<ull>::max() int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ull h, w; cin >> h >> w; int n; cin >> n; ull d; ull res; cin >> d; if (w % d != 0 || h % d != 0) { cout << -1; return 0; } res = (w / d) * (h / d); w /= d; h /= d; for (int i = 1; i < n; i++) { int prevD = d; cin >> d; int artD = d / prevD; res -= (w / artD) * (h / artD) * (artD * artD - 1); w /= artD; h /= artD; } cout << res; return 0; } |