#include <cstdio> using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define INT(x) int x; scanf("%d", &x) typedef long long LL; int d[30]; int main() { INT(h); INT(w); INT(n); REP(i,n) scanf("%d", &d[i]); if (h % d[0] || w % d[0]) { printf("-1\n"); return 0; } h /= d[0]; w /= d[0]; LL r = LL(h) * w; REP(i,n-1) { LL p = d[i + 1] / d[i]; h /= p; w /= p; r -= LL(h) * w * (p * p - 1); } printf("%lld\n", r); }
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 <cstdio> using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define INT(x) int x; scanf("%d", &x) typedef long long LL; int d[30]; int main() { INT(h); INT(w); INT(n); REP(i,n) scanf("%d", &d[i]); if (h % d[0] || w % d[0]) { printf("-1\n"); return 0; } h /= d[0]; w /= d[0]; LL r = LL(h) * w; REP(i,n-1) { LL p = d[i + 1] / d[i]; h /= p; w /= p; r -= LL(h) * w * (p * p - 1); } printf("%lld\n", r); } |