#include <bits/stdc++.h> #ifdef dbg #define D(...) fprintf(stderr, __VA_ARGS__) #define DD(...) D(#__VA_ARGS__ " = "), debug_helper::debug(__VA_ARGS__), D("\n") #include "C:\Users\wsyear\Desktop\OI\templates\debug.hpp" #else #define D(...) ((void)0) #define DD(...) ((void)0) #endif #define rep(i, j, k) for (int i = (j); i <= (k); ++i) #define per(i, j, k) for (int i = (j); i >= (k); --i) #define SZ(v) int((v).size()) #define ALL(v) (v).begin(),(v).end() #define fi first #define se second using ll = long long; using pii = std::pair<int, int>; using pll = std::pair<ll, ll>; using namespace std; const int maxn = 110; int h, w, n, a[maxn]; int main() { cin.tie(nullptr) -> ios::sync_with_stdio(false); cin >> h >> w >> n; rep (i, 1, n) cin >> a[i]; if (h % a[1] != 0 || w % a[1] != 0) return cout << "-1\n", 0; ll ans = 1ll * (h / a[1]) * (w / a[1]); rep (i, 2, n) { ll delta = 1ll * (a[i] / a[i - 1]) * (a[i] / a[i - 1]) - 1; ans -= delta * (h / a[i]) * (w / a[i]); } cout << ans << '\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 35 36 37 | #include <bits/stdc++.h> #ifdef dbg #define D(...) fprintf(stderr, __VA_ARGS__) #define DD(...) D(#__VA_ARGS__ " = "), debug_helper::debug(__VA_ARGS__), D("\n") #include "C:\Users\wsyear\Desktop\OI\templates\debug.hpp" #else #define D(...) ((void)0) #define DD(...) ((void)0) #endif #define rep(i, j, k) for (int i = (j); i <= (k); ++i) #define per(i, j, k) for (int i = (j); i >= (k); --i) #define SZ(v) int((v).size()) #define ALL(v) (v).begin(),(v).end() #define fi first #define se second using ll = long long; using pii = std::pair<int, int>; using pll = std::pair<ll, ll>; using namespace std; const int maxn = 110; int h, w, n, a[maxn]; int main() { cin.tie(nullptr) -> ios::sync_with_stdio(false); cin >> h >> w >> n; rep (i, 1, n) cin >> a[i]; if (h % a[1] != 0 || w % a[1] != 0) return cout << "-1\n", 0; ll ans = 1ll * (h / a[1]) * (w / a[1]); rep (i, 2, n) { ll delta = 1ll * (a[i] / a[i - 1]) * (a[i] / a[i - 1]) - 1; ans -= delta * (h / a[i]) * (w / a[i]); } cout << ans << '\n'; } |