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
#include <iostream>
#include <vector>

using namespace std;

typedef vector<long long> vL;

int main(int argc, char* argv[])
{
#ifdef _DEBUG
	freopen("input.txt", "rt", stdin);
#endif
	long long h, w;
	cin >> h >> w;
	int n;
	cin >> n;
	vL sz(n);
	for (int i = 0; i < n; i++)
		cin >> sz[i];
	if (h % sz[0] != 0 || w % sz[0] != 0) {
		cout << "-1" << endl;
		return 0;
	}
	long long res = (h / sz[0]) * (w / sz[0]);
#ifdef _DEBUG
	cerr << "0\t" << res << endl;
#endif
	for (int i = 1; i < n && sz[i] <= h && sz[i] <= w; i++) {
		long long nextSqrNum = (h / sz[i]) * (w / sz[i]);
		long long koef = sz[i] / sz[i - 1];
		res += (1 - koef*koef) * nextSqrNum;
#ifdef _DEBUG
		cerr << i << "\t" << res << endl;
#endif
	}
	cout << res << endl;
	return 0;
}