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 <bits/stdc++.h>

using namespace std;

int main(){

    int a, b, n;
    cin>>a>>b>>n;
    
    vector<int> sizes(n);
    for(auto&x:sizes)cin>>x;

    int u = sizes[0];

    if(a%u != 0 || b%u != 0){
        cout << "-1\n";
        return 0;
    }

    a /= u;
    b /= u;
    long long res = a*1LL*b;
    //cout<<"wun:"<<a<<" "<<b<<" "<<res<<endl;
    
    for(int i=1;i<n;i++){
        int u = sizes[i-1];
        int x = sizes[i];
        long long rat = x/u;
        a /= rat, b /= rat;
        res -= a*1LL*b * (rat*rat-1);
        //cout<<"wun:"<<a<<" "<<b<<" "<<res<<endl;
    }

    cout <<res<<endl;

}