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 <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main(void)
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	ll h, w, n;
	cin >> h >> w >> n;
	vector<ll> d(n);
	for (ll i = 0; i < n; i++)
		cin >> d[i];

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

	ll wynik = (h * w) / (d[0] * d[0]);
	for (ll i = 1; i < n; i++) {
		ll ileH = h / d[i];
		ll ileW = w / d[i];
		ll K = (d[i]*d[i]) / (d[i-1]*d[i-1]);
		wynik -= K * ileH * ileW;
		wynik += ileH * ileW;
	}

	cout << wynik << '\n';

	return 0;
}