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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int h, w;
	cin >> h >> w;

	int n;
	cin >> n;

	vector<int> d(n);
	for(int i = 0; i < n; i++) cin >> d[i];

	if(w%d[0]!=0||h%d[0]!=0){
		cout << -1 << '\n';
		return 0;
	}

	h/=d[0];
	w/=d[0];

	ll ans = (ll)h*w;

	for(int i = 1; i < n; i++){
		int temp = d[i];
		d[i]/=d[i-1];
		int w1 = w/d[i];
		int h1 = h/d[i];
		ans -= (ll)w1 * h1 * d[i] * d[i];
		ans += (ll)w1 * h1;
		w = w1;
		h = h1;
		d[i] = temp;
	}
	
	cout << ans << '\n';

	return 0;
}