#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using ld = long double;
#define int ll
#define sz(x) ((int)(x).size())
using pii = pair<int,int>;
using tii = tuple<int,int,int>;
signed main() {
cin.tie(0) -> sync_with_stdio(0);
int n, H, W;
cin >> H >> W >> n;
vector<int> v(n);
for(auto &x : v) cin >> x;
reverse(all(v));
ll rez = 0;
while(sz(v) > 1) {
int a = v.back();
v.pop_back();
//cerr << a << '\n';
if(H % a != 0 || W % a != 0) {
cout << "-1\n";
return 0;
}
//cerr << v.back() << '\n';
int h = H % v.back(), w = W % v.back();
rez += (h * W + w * H - h * w) / (a * a);
//cerr << h << ' ' << w << ' ' << H << ' ' << W << '\n';
H -= h;
W -= w;
}
if(H % v.back() != 0 || W % v.back() != 0) {
cout << "-1\n";
return 0;
}
rez += H * W / (v.back() * v.back());
cout << rez << '\n';
}
/**
Anul asta nu se da centroid
-- Rugaciunile mele
*/
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 47 48 49 50 51 52 53 54 55 56 | #include <bits/stdc++.h> #define all(x) (x).begin(),(x).end() using namespace std; using ll = long long; using ld = long double; #define int ll #define sz(x) ((int)(x).size()) using pii = pair<int,int>; using tii = tuple<int,int,int>; signed main() { cin.tie(0) -> sync_with_stdio(0); int n, H, W; cin >> H >> W >> n; vector<int> v(n); for(auto &x : v) cin >> x; reverse(all(v)); ll rez = 0; while(sz(v) > 1) { int a = v.back(); v.pop_back(); //cerr << a << '\n'; if(H % a != 0 || W % a != 0) { cout << "-1\n"; return 0; } //cerr << v.back() << '\n'; int h = H % v.back(), w = W % v.back(); rez += (h * W + w * H - h * w) / (a * a); //cerr << h << ' ' << w << ' ' << H << ' ' << W << '\n'; H -= h; W -= w; } if(H % v.back() != 0 || W % v.back() != 0) { cout << "-1\n"; return 0; } rez += H * W / (v.back() * v.back()); cout << rez << '\n'; } /** Anul asta nu se da centroid -- Rugaciunile mele */ |
English