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
#include <stdio.h>


int main()
{
int x,y,n;
int s;
int a,b;
int z;

scanf ("%d",&x);
scanf ("%d",&y);
scanf ("%d",&n);

scanf ("%d",&a);

if( (x/a)*a == x && (y/a)*a == y )
{
  s=x/a * y/a;
  for(int i=1;i<n;i++)
  {
    scanf ("%d",&b);
    z=(x/b) * (y/b);
    s=s+z-z*b/a*b/a;
    a=b;
  }
}
else
 s=-1;
printf ("%d\n",s);
return 0;
}