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
39
40
41
42
43
44
45
46
47
48
#include <bits/stdc++.h>
#define ft first
#define sc second
#define pb push_back
#define FOR(i,n) for(int i=0; i<n; i++)
#define FORX(i,a,b) for(int i=(a); i<=(b); i++)
#define watch(x) cerr << (#x) << " == " << (x) << endl
typedef long long ll;
typedef long double ld;
using namespace std;

ll d[50];

int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

ll h,w;
cin>>h>>w;

ll n;
cin>>n;

FOR(i,n){
    cin>>d[i];
}

if (h%d[0] || w%d[0]){
    cout<<"-1";
    return 0;
}

ll sum = (h/d[0])*(w/d[0]);
ll a = h, b = w;

FORX(i,1,n-1){
    a -= a%d[i];
    b -= b%d[i];
    if (!a || !b) {break;}
    sum -= (a/d[i-1])*(b/d[i-1]);
    sum += (a/d[i])*(b/d[i]);
}

cout << sum;

return 0;
}