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
44
45
46
47
48
49
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

set<LL> sq;
LL ans;
bool dasie;

void solve(LL h, LL w)
{
	if (h == 0 || w == 0)
		return;
	auto it = sq.upper_bound(min(h, w));
	if (it == sq.begin())
	{
		dasie = 0;
		return;
	}
	it--;
	LL a = *it;
	ans += (h/a)*(w/a);
	LL ha = h/a*a;
	LL wa = w/a*a;
	solve(h-ha, wa);
	solve(h, w-wa);
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);

	LL h, w;
	cin >> h >> w;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		LL k;
		cin >> k;
		sq.insert(k);
	}
	ans = 0;
	dasie = 1;
	solve(h, w);
	if (!dasie)
		cout << "-1\n";
	else
		cout << ans << "\n";
}