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
#include<bits/stdc++.h>

using namespace std;

vector<long long int> inp;

int main() {
    long long int h, w, n;
    cin >> h >> w >> n;

    for(int i = 0; i < n; i++) {
        int tmp;
        cin >> tmp;
        inp.push_back(tmp);
    }


    if(h % inp[0] != 0 or w % inp[0] != 0){
        cout << "-1";
        return 0;
    }

    long long int result = (h / inp[0]) * (w / inp[0]);


    for(int i = 1 ; i < inp.size(); i++){
        long long int tmp =   (long long int)(h / inp[i]) * (long long int)(w / inp[i]);
        result -= tmp * (long long int)(pow(inp[i] / inp[i-1], 2));
        result += tmp;
        w = (long long int)(w / inp[i]) * inp[i];
        h = (long long int)(h / inp[i]) * inp[i];
    }

    cout << result << '\n';

    return 0;
}