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
#include <bits/stdc++.h>
#define int long long
#define FOR(i,a,b) for(int i = a; i < b;++i)
#define pb emplace_back
using namespace std;
int32_t main(){
    int h,w;
    cin>>h >>w;
    int n;
    cin>>n;
    vector<int> V;
    FOR(i,0,n){
        int x;
        cin>>x;
        V.pb(x);
    }
    if(h % V[0] != 0 || w % V[0] != 0){
        cout<<-1;
        return 0;
    }
    int wyn = (h / V[0]) * (w / V[0]);
    FOR(i,1,V.size()){
        if(h >= V[i] && w >= V[i]){
            int h1 = h - (h % V[i]);
            int w1 = w - (w % V[i]);
            wyn-=(h1 / V[i - 1]) * (w1 / V[i - 1]);
            wyn+=(h1 / V[i]) * (w1 / V[i]);
            h = h1;
            w = w1;
        }
    }
    cout<<wyn;
}