1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#include <cstdio>

static long long w, h, n, i, d[30], x, y, r;

int main(void)
{
	scanf("%lld%lld%lld", &w, &h, &n);
	for (i = 0; i < n; i++)
		scanf("%lld", &d[i]);
	for (i--; i >= 0; i--) {
		long long dd = d[i], xx = w / dd, yy = h / dd;

		r += xx * yy - x / dd * y / dd;
		x = xx * dd;
		y = yy * dd;
	}

	printf("%lld\n", x == w && y == h ? r : -1);
	return 0;
}