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
33
34
35
36
37
38
#include<bits/stdc++.h>

#define FOR(i,s,e) for(int i=(s); i<=(e); i++)
#define FORD(i,s,e) for(int i=(s); i>=(e); i--)
#define ALL(k) (k).begin(), (k).end()
#define e1 first
#define e2 second
#define mp make_pair
 
using namespace std;
using LL=long long;
using LD=long double;
using PII=pair<int,int>;

int ds[44];

int main(){
    int w, h; scanf("%d%d",&w,&h);

    int n;scanf("%d",&n);
    FOR(i,1,n){
        scanf("%d",&ds[i]);
    }
    if (w % ds[1] != 0 || h % ds[1] != 0){
        printf("%d\n", -1);
        return 0;
    }
    LL used_w = 0, used_h = 0;
    LL ans = 0;
    FORD(i,n,1){
        LL fill_w = w / ds[i], prefilled_w = used_w / ds[i];
        LL fill_h = h / ds[i], prefilled_h = used_h / ds[i];
        ans += (fill_w * fill_h) - (prefilled_h * prefilled_w);
        used_w = fill_w * ds[i];
        used_h = fill_h * ds[i];
    }
    printf("%lld\n", ans);
}