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
#include<iostream>
#include<vector>

using namespace std;

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

    for (int i = 0; i < n; i++) {
        cin >> sizes[i];
    }

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

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

    for (int i = 1; i < n; i++) {
        long long hStack = h / sizes[i];
        long long wStack = w / sizes[i];

        result -= ((sizes[i] / sizes[i-1]) * (sizes[i] / sizes[i-1]) - 1) * hStack * wStack;
    }

    cout << result << endl;
}