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
#include <iostream>
#include <vector>
using namespace std;

int main()
{
	long long w,h,n;
	cin >> w >> h >> n;
	vector<long long> t(n);
	for(int i = 0; i < n; i++) {
		cin >> t[i];
	}
	
	long long ret = 0;
	if(w%t[0] || h%t[0]) {
		ret = -1;
	}
	else {
		ret = (long long)(w / t[0])* (long long)(h / t[0]);
		for(int i = 1; i < n; i++) {

			long long r = t[i] / t[i-1];
			long long d  = r * r  - 1LL;
			long long nw = w / t[i];
			long long nh = h / t[i];
			long long e = nw * nh * d;
			if(e == 0) {
				break;
			}
			ret -= e;
		}
	}

	cout << ret << "\n";
	return 0;
}