/*
* Author: toko
* Time: 2024-03-14 19:46:50
*/
#ifndef DEBUG
#define NDEBUG
#pragma GCC optimize("Ofast,unroll-loops")
#else
#pragma GCC optimize("Og")
#endif
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
iostream::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
long long h, w, n;
cin >> h >> w >> n;
vector<long long> d(n);
for (int i = 0; i < n; i++)
cin >> d[i];
sort(d.begin(), d.end());
if (h % d[0] != 0 || w % d[0] != 0)
{
cout << -1 << endl;
return 0;
}
long long cnt = 0;
for (int i = 1; i < n; i++)
{
long long n_w = w / d[i] * d[i];
long long n_h = h / d[i] * d[i];
cnt += (w * h - n_w * n_h) / d[i - 1] / d[i - 1];
w = n_w;
h = n_h;
}
cnt += (w * h) / d[n - 1] / d[n - 1];
cout << cnt << 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 | /* * Author: toko * Time: 2024-03-14 19:46:50 */ #ifndef DEBUG #define NDEBUG #pragma GCC optimize("Ofast,unroll-loops") #else #pragma GCC optimize("Og") #endif #include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { iostream::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); long long h, w, n; cin >> h >> w >> n; vector<long long> d(n); for (int i = 0; i < n; i++) cin >> d[i]; sort(d.begin(), d.end()); if (h % d[0] != 0 || w % d[0] != 0) { cout << -1 << endl; return 0; } long long cnt = 0; for (int i = 1; i < n; i++) { long long n_w = w / d[i] * d[i]; long long n_h = h / d[i] * d[i]; cnt += (w * h - n_w * n_h) / d[i - 1] / d[i - 1]; w = n_w; h = n_h; } cnt += (w * h) / d[n - 1] / d[n - 1]; cout << cnt << endl; return 0; } |
English