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
#include<cstdio>
#include<vector>


using namespace std;
int main(){
long long int h,w,h1,w1,res=0;
int n,d,D;
scanf("%lld%lld\n",&h,&w);
scanf("%d\n", &n);
scanf("%d", &D);

if (h%D != 0 or w%D!=0){
    printf("-1");
    return 0;
}
while(n>1){
    d = D;
    scanf("%d", &D);
    h1 = h % D;
    w1 = w % D;
    res += (h1/d) * (w/d) + (w1/d) * (h/d) - (w1/d) *(h1/d);
    n--;
    w -= w1;
    h -= h1;
}
    res += w/D * h/D;
    printf("%lld", res);
return 0;
}