#include <bits/stdc++.h> #define pb push_back #define inf 999999999 #define int long long #define turbo ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); using namespace std; vector<int> squares; signed main() { turbo; int h, w; cin >> h >> w; int t; cin >> t; for (int i = 0; i < t; i++) { int x; cin >> x; squares.pb(x); } if (h % squares[0] != 0 || w % squares[0] != 0) { cout << -1; return 0; } int wsquares = w / squares[0]; int hsquares = h / squares[0]; int ans = wsquares * hsquares; for (int i = 1; i < t; i++) { int scalar = squares[i] / squares[i - 1]; int wsquares_new = wsquares / scalar; int hsquares_new = hsquares / scalar; if (wsquares_new == 0 || hsquares_new == 0) { break; } ans -= (wsquares_new * scalar) * (hsquares_new * scalar); ans += wsquares_new * hsquares_new; wsquares = wsquares_new; hsquares = hsquares_new; } cout << ans; 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 41 42 43 44 45 46 | #include <bits/stdc++.h> #define pb push_back #define inf 999999999 #define int long long #define turbo ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); using namespace std; vector<int> squares; signed main() { turbo; int h, w; cin >> h >> w; int t; cin >> t; for (int i = 0; i < t; i++) { int x; cin >> x; squares.pb(x); } if (h % squares[0] != 0 || w % squares[0] != 0) { cout << -1; return 0; } int wsquares = w / squares[0]; int hsquares = h / squares[0]; int ans = wsquares * hsquares; for (int i = 1; i < t; i++) { int scalar = squares[i] / squares[i - 1]; int wsquares_new = wsquares / scalar; int hsquares_new = hsquares / scalar; if (wsquares_new == 0 || hsquares_new == 0) { break; } ans -= (wsquares_new * scalar) * (hsquares_new * scalar); ans += wsquares_new * hsquares_new; wsquares = wsquares_new; hsquares = hsquares_new; } cout << ans; return 0; } |