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
#include <iostream>
#include <vector>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    long long h, w, n;
    cin >> h >> w >> n;
    vector<long long> O(n);
    for (auto& o : O)
        cin >> o;

    long long covered_area = 0, result = 0;
    for (int i=n-1; i>=0; i--) {
        auto x = O[i];
        long long area = ((h/x)*x) * ((w/x)*x);
        result += (area-covered_area) / (x*x);
        covered_area = area;
    }
    if (covered_area == h*w)
        cout << result << '\n';
    else
        cout << "-1\n";

    return 0;
}