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
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define st first
#define nd second
int main()
{
    ll h,w;
    cin>>h>>w;
    ll n;
    cin>>n;
    vector<ll>a(n);
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    if(w%a[0] or h%a[0])
    {
        cout<<-1<<endl;
        return 0;
    }
    h/=a[0];w/=a[0];
    ll wyn=h*w;
    for(int i=1;i<n;i++)
    {
        w=(w*a[i-1])/a[i];
        h=(h*a[i-1])/a[i];
        wyn-=(h*w)*(a[i]/a[i-1])*(a[i]/a[i-1])-(h*w);
    }
    cout<<wyn<<endl;
}