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
47
48
49
50
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

#define P(a,n) for(int j=a;j<n;j++)
#define P3(a,n,z) for(int z=a;z<n;z++)
#define PD(pocz,kon,z) for(int z=pocz;z>=kon;z--)
#define W while

#define PB push_back
#define F first
#define S second
#define ll long long

#define O cout<<
#define I cin>>
#define endl '\n'
#define E '\n'

using namespace std;
//


int main()
{
ios_base::sync_with_stdio(0); cin.tie(NULL);
ll h,w,n,d,nd,il=0;
I h>>w>>n;
I d;
if(w%d!=0 || h%d!=0)
{ O -1; return 0;}
h/=d;w/=d;
P(1,n)
{
    I nd; nd/=d;
    il+=(h*w-(h/nd)*nd*(w/nd)*nd);
    h/=nd;w/=nd;
    d*=nd;
   // O h<<' '<<w<<' '<<d<<' '<<il<<E;
}
il+=h*w;
O il;





return 0;
}