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

int d[35];

int main()
{
    int a, b, n;
    cin >> a >> b >> n;
    for (int i = 0; i<n; i++)
    {
        cin >> d[i];
    }
    int sum = 0;
    if (a%d[0]==0 and b%d[0]==0)
    {
        sum = 0;
        int act = (a*b);
        for (int i = n-1; i>=0; i--)
        {
            if (d[i]<=a and d[i]<=b)
            {
                sum += act/(d[i]*d[i]);
                act =act%(d[i]*d[i]);
            }
        }
        cout << sum+act;
    }
    else
    {
        cout << -1;
    }
}