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

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cout.tie(NULL);
    long long h, w, n;
    std::cin >> h >> w;
    std::cin >> n;
    long long obr[n];
    long long sum=0, x=0, y=0;
    for (int i=n-1; i>=0; i--) {
        std::cin >> obr[i];
    }
    if ((h%obr[n-1]!=0) || (w%obr[n-1]!=0)) {
        std::cout << -1 << '\n';
        return 0;
    }
    for (int i=0; i<n; i++) {
        sum+=((h/obr[i])*(w/obr[i]))-((x/obr[i])*(y/obr[i]));
        x=h-(h%obr[i]);
        y=w-(w%obr[i]);
    }
    std::cout << sum;
    return 0;
}