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

const int MAX = 31;
int64_t D[MAX];


int main() {
    std::ios_base::sync_with_stdio(0);
    int64_t h,w,n;
    std::cin >> h >> w >> n;
    for (int i=0;i<n;++i) std::cin >> D[i];
    std::sort(D,D+n);
    if (h%D[0] > 0 || w%D[0] > 0) {
        std::cout << "-1" << std::endl;
        return 0;
    }
    int64_t s = (h/D[0]) * (w/D[0]);
    for (int i=1;i<n;++i) {
        int64_t ss = (h/D[i]) * (w/D[i]);
        s -= ss*D[i]*D[i]/D[i-1]/D[i-1];
        s += ss;
    }
    std::cout << s << std::endl;
    return 0;
}