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<bits/stdc++.h>
using namespace std;
#define int long long
inline int read(){
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
int a[53],x[53],y[53];
signed main()
{
	int A=read(),B=read(),n=read();
	for(int i=1; i<=n; ++i) a[i]=read();
	if(A%a[1]||B%a[1]) puts("-1"),exit(0);
	for(int i=1; i<=n; ++i) x[i]=A/a[i],y[i]=B/a[i];
	int ans=x[n]*y[n];
	for(int i=1; i<n; ++i)
	{
		int t=a[i+1]/a[i];
		int u=x[i]*y[i];
		int v=x[i+1]*y[i+1]*t*t;
		ans+=u-v;
	}
	printf("%lld\n",ans);
	return 0;
}