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

using namespace std;

typedef long long ll;

int main()
{
    ll r = 0;
    ll h, w;
    cin >> h >> w;
    ll n;
    cin >> n;
    ll d[n];
    for (int i = 0; i < n; i++)
    {
        cin >> d[i];
    }
    if (h % d[0] != 0 || w % d[0] != 0)
    {
        cout << "-1\n";
        return 0;
    }
    for (int i = 1; i < n; i++)
    {
        ll a, b;
        a = w - w % d[i];
        b = h - h % d[i];
        r += (w * h - a * b) / (d[i-1] * d[i-1]);
        w = a;
        h = b;
    }
    r += (w * h) / (d[n-1] * d[n-1]);
    cout << r << "\n";
    return 0;
}