// Kacper Orszulak #ifndef DEBUG #define NDEBUG #endif #include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vll = vector<ll>; using vb = vector<bool>; using vvi = vector<vi>; using vvll = vector<vll>; #define st first #define nd second #define pb push_back #define rep(i, n) for (int i = 0; i < int(n); ++i) #define whole(x) x.begin(), x.end() [[maybe_unused]] constexpr int INF = 1e9+7; template<class T> bool minR(T &a, const T &b) { if (b < a) { a = b; return true; } else return false; } template<class T> bool maxR(T &a, const T &b) { if (b > a) { a = b; return true; } else return false; } int h, w; int n; vi arr; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin >> h >> w; cin >> n; arr.resize(n); for (int &e : arr) cin >> e; if (h % arr[0] != 0 or w % arr[0] != 0) { cout << "-1\n"; return 0; } ll result = ll(h / arr[0]) * ll(w / arr[0]); for (int i = 1; i < n; ++i) { ll cntY = h / arr[i]; ll cntX = w / arr[i]; ll smallerCntY = cntY * ll(arr[i] / arr[i-1]); ll smallerCntX = cntX * ll(arr[i] / arr[i-1]); result -= smallerCntY * smallerCntX; result += cntY * cntX; } cout << result << '\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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | // Kacper Orszulak #ifndef DEBUG #define NDEBUG #endif #include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vll = vector<ll>; using vb = vector<bool>; using vvi = vector<vi>; using vvll = vector<vll>; #define st first #define nd second #define pb push_back #define rep(i, n) for (int i = 0; i < int(n); ++i) #define whole(x) x.begin(), x.end() [[maybe_unused]] constexpr int INF = 1e9+7; template<class T> bool minR(T &a, const T &b) { if (b < a) { a = b; return true; } else return false; } template<class T> bool maxR(T &a, const T &b) { if (b > a) { a = b; return true; } else return false; } int h, w; int n; vi arr; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin >> h >> w; cin >> n; arr.resize(n); for (int &e : arr) cin >> e; if (h % arr[0] != 0 or w % arr[0] != 0) { cout << "-1\n"; return 0; } ll result = ll(h / arr[0]) * ll(w / arr[0]); for (int i = 1; i < n; ++i) { ll cntY = h / arr[i]; ll cntX = w / arr[i]; ll smallerCntY = cntY * ll(arr[i] / arr[i-1]); ll smallerCntX = cntX * ll(arr[i] / arr[i-1]); result -= smallerCntY * smallerCntX; result += cntY * cntX; } cout << result << '\n'; } |