#include <bits/stdc++.h> using namespace std; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(0); long long h, w; cin >> h >> w; long long n; cin >> n; vector<long long> sizes; for (int i = 0; i < n; i++) { long long in; cin >> in; sizes.push_back(in); } if (h % sizes[0] != 0 or w % sizes[0] != 0) { cout << -1 << endl; return 0; } vector<long long> boxes_ver; vector<long long> boxes_hor; long long h_left = h; long long w_left = w; for (int i = sizes.size() - 1; i >= 0; i--) { boxes_ver.push_back(h_left / sizes[i]); h_left = h_left % sizes[i]; boxes_hor.push_back(w_left / sizes[i]); w_left = w_left % sizes[i]; } // for (const auto& i : boxes_ver) { // cout << i << " "; // } // cout << endl; // for (const auto& i : boxes_hor) { // cout << i << " "; // } // cout << endl; long long counter = 0; for (int i = 0; i < sizes.size(); i++) { // cout << "box size " << sizes[i] << endl; // cout << boxes_ver[sizes.size() - 1 - i] << " " << boxes_hor[sizes.size() - 1 - i] << endl; long long tmp = 0; tmp += boxes_ver[sizes.size() - 1 - i] * (w / sizes[i]); tmp += boxes_hor[sizes.size() - 1 - i] * (h / sizes[i]); tmp -= boxes_ver[sizes.size() - 1 - i] * boxes_hor[sizes.size() - 1 - i]; // cout << "tmp " << tmp << endl; counter += tmp; } cout << counter << endl; return 0; }
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 | #include <bits/stdc++.h> using namespace std; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(0); long long h, w; cin >> h >> w; long long n; cin >> n; vector<long long> sizes; for (int i = 0; i < n; i++) { long long in; cin >> in; sizes.push_back(in); } if (h % sizes[0] != 0 or w % sizes[0] != 0) { cout << -1 << endl; return 0; } vector<long long> boxes_ver; vector<long long> boxes_hor; long long h_left = h; long long w_left = w; for (int i = sizes.size() - 1; i >= 0; i--) { boxes_ver.push_back(h_left / sizes[i]); h_left = h_left % sizes[i]; boxes_hor.push_back(w_left / sizes[i]); w_left = w_left % sizes[i]; } // for (const auto& i : boxes_ver) { // cout << i << " "; // } // cout << endl; // for (const auto& i : boxes_hor) { // cout << i << " "; // } // cout << endl; long long counter = 0; for (int i = 0; i < sizes.size(); i++) { // cout << "box size " << sizes[i] << endl; // cout << boxes_ver[sizes.size() - 1 - i] << " " << boxes_hor[sizes.size() - 1 - i] << endl; long long tmp = 0; tmp += boxes_ver[sizes.size() - 1 - i] * (w / sizes[i]); tmp += boxes_hor[sizes.size() - 1 - i] * (h / sizes[i]); tmp -= boxes_ver[sizes.size() - 1 - i] * boxes_hor[sizes.size() - 1 - i]; // cout << "tmp " << tmp << endl; counter += tmp; } cout << counter << endl; return 0; } |