// Witold Milewski
// PA 2024
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=a; i<=b; ++i)
const int maxn=37;
int d[maxn], X[maxn];
int x, y, n;
int32_t main() {
cin.tie(0) -> ios_base::sync_with_stdio(0);
cin >> x >> y;
if(y>x) swap(x, y);
// x mniejszy
cin >> n;
FOR(i, 1, n) cin>>d[i];
FOR(i, 2, n) X[i]=d[i]/d[i-1];
if(x%d[1]!=0 || y%d[1]!=0) {
cout << "-1\n";
return 0;
}
int res = (x/d[1])*(y/d[1]);
FOR(i, 2, n) {
int a = x/d[i];
int b = y/d[i];
res -= a*X[i]*b*X[i];
res += a*b;
}
cout << res << '\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 32 33 34 | // Witold Milewski // PA 2024 #include <bits/stdc++.h> using namespace std; #define int long long #define FOR(i, a, b) for(int i=a; i<=b; ++i) const int maxn=37; int d[maxn], X[maxn]; int x, y, n; int32_t main() { cin.tie(0) -> ios_base::sync_with_stdio(0); cin >> x >> y; if(y>x) swap(x, y); // x mniejszy cin >> n; FOR(i, 1, n) cin>>d[i]; FOR(i, 2, n) X[i]=d[i]/d[i-1]; if(x%d[1]!=0 || y%d[1]!=0) { cout << "-1\n"; return 0; } int res = (x/d[1])*(y/d[1]); FOR(i, 2, n) { int a = x/d[i]; int b = y/d[i]; res -= a*X[i]*b*X[i]; res += a*b; } cout << res << '\n'; } |
English