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

using namespace std;

int main() {

    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);

    int h, w, n;
    cin >> h >> w >> n;

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

    int ileob[n+1], pole = 0;

    ileob[n-1] = (h / obr[n-1]) * (w / obr[n-1]);
    pole = ileob[n-1] * obr[n-1] * obr[n-1];

    int sumob = ileob[n-1];

    for (int i = n - 2; i >= 0; i--) {
        ileob[i] = (h / obr[i]) * (w / obr[i]);
        pole = ileob[i] * obr[i] * obr[i];
        sumob += ileob[i] - (obr[i+1] / obr[i]) * (obr[i+1] / obr[i]) * ileob[i+1];
    }

    if (pole != w * h) {
        cout << -1;
        return 0;
    }

    cout << sumob << " ";

    return 0;
}