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

int main()
{
	long long a,b,n,res=0, d;
	scanf("%lld%lld%lld", &a, &b, &n);
	scanf("%lld", &d);
	if(a%d!=0 || b%d!=0){
		printf("-1\n");
		return 0;
	}
	while(n>1){
		long long e;scanf("%lld", &e);
		long long A, B;
		A = a-a%e;
		B = b-b%e;
		res+=(a*b-(A*B))/d/d;
		d = e;
		a = A;
		b = B;
		n--;
	}
	res+=a*b/d/d;
	printf("%lld\n", res);
}