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 <map>

#define REP(a, n) for (int a = 0; a < (n); ++a)
#define FOR(a, b, c) for (int a = (b); a <= (c); ++a)

using namespace std;

typedef long long LL;

//////////////////////

LL X,Y,N,roz[40];

int main() {
    scanf("%Ld%Ld%Ld", &X, &Y, &N);
    REP(a, N)
        scanf("%Ld", roz+a);
    if (X%roz[0] || Y%roz[0])
        printf("-1\n");
    else {
        LL wyn = (X/roz[0])*(Y/roz[0]);
        FOR(a, 1, N-1) {
            LL px = X/roz[a], py = Y/roz[a];
            wyn -= (px*roz[a]/roz[a-1])*(py*roz[a]/roz[a-1]);
            wyn += px*py;
        }
        printf("%lld\n", wyn);
    }
}