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
37
38
39
40
41
42
43
44
45
46
#include <bits/stdc++.h>

using namespace std;
vector<unsigned long long> tab;
 unsigned long long int x;
unsigned long long int don;
unsigned long long int ilo;
unsigned long long wyn;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    unsigned long long int t;
    int temp=0;
    unsigned long long int a,b;
   unsigned long long int n,m;
   cin>>n>>m;
   int k;
   cin>>k;
   for(int i=0;i<k;i++){
   cin>>x;
   tab.push_back(x);
   }

   sort(tab.begin(),tab.end());
   if(n%tab[0]!=0 || m%tab[0]!=0){
    cout<<"-1";
    return 0;
   }
      a=n/tab[0];
   b=m/tab[0];
   wyn=(a*b);
   //cout<<wyn<<endl;
   for(int i=1;i<tab.size();i++){
    if(tab[i]<=n && tab[i]<=m){
            t=(tab[i]*tab[i])/(tab[i-1]*tab[i-1]);
        a=n/tab[i];
        b=m/tab[i];
        wyn-=(t-1)*(a*b);
        //cout<<wyn<<endl;
    }
   }

    cout<<wyn;
    return 0;
}