#include <iostream> #include <vector> int main() { long long h, w; std::cin >> h >> w; long long n; std::cin >> n; std::vector<long long> a(n); for (int i = 0; i < n; i++) { std::cin >> a[i]; } if (h % a[0] != 0 || w % a[0] != 0){ std::cout<<"-1"; return 0; } long long currenth = 0, currentw = 0, ans = 0; long long cntv, cnth; for (int i = n-1; i >=0; i--){ cnth = (h - currenth)/a[i]; cntv = (w - currentw)/a[i]; ans += cntv *currenth/a[i] + cnth * currentw/a[i] + cntv*cnth; currenth += cnth * a[i]; currentw += cntv * a[i]; } std::cout<<ans; }
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 | #include <iostream> #include <vector> int main() { long long h, w; std::cin >> h >> w; long long n; std::cin >> n; std::vector<long long> a(n); for (int i = 0; i < n; i++) { std::cin >> a[i]; } if (h % a[0] != 0 || w % a[0] != 0){ std::cout<<"-1"; return 0; } long long currenth = 0, currentw = 0, ans = 0; long long cntv, cnth; for (int i = n-1; i >=0; i--){ cnth = (h - currenth)/a[i]; cntv = (w - currentw)/a[i]; ans += cntv *currenth/a[i] + cnth * currentw/a[i] + cntv*cnth; currenth += cnth * a[i]; currentw += cntv * a[i]; } std::cout<<ans; } |