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

using namespace std;

#define ll long long

ll h, w,prevd;
int n;
int main()
{
	ll sum = 0;
	cin >> h >> w >> n>>prevd;
	if (h % prevd != 0 || w % prevd != 0) {
		cout << -1; return 0;
	}
	w /= prevd; h /= prevd;
	ll d;
	for (int i = 1; i < n; i++)
	{
		cin >> d; d /= prevd;
		sum += h * w - (h - h % d) * (w - w % d);
		prevd = d * prevd;
		w /= d; h /= d;

	}
	sum += h * w;
	cout << sum;

}