1 #include<iostream>
2 #include<string>
3 #include<algorithm>
4 #include<cstdio>
5 #include<cstring>
6 #include<cstdlib>
7 #include<cmath>
8 #include<bitset>
9 using namespace std;
10 typedef long long s64;
11
12 const int ONE = 50005;
13 const int MOD = 1e9 + 7;
14 const int Niyu = 166666668;
15
16 s64 A, B, D;
17 int P[ONE],num;
18 int vis[ONE];
19 s64 Ans;
20
21 int get()
22 {
23 int res=1,Q=1;char c;
24 while( (c=getchar())<48 || c>57 )
25 if(c==‘-‘)Q=-1;
26 res=c-48;
27 while( (c=getchar())>=48 && c<=57 )
28 res=res*10+c-48;
29 return res*Q;
30 }
31
32 void Factor(int x)
33 {
34 for(int i=2; i*i<=x; i++)
35 if(x % i == 0)
36 {
37 P[++num] = i;
38 while(x % i == 0) x /= i;
39 }
40 if(x != 1) P[++num] = x;
41 }
42
43 int Calc(int n)
44 {
45 return (s64)n * (n+1) % MOD * (2*n+1) % MOD * Niyu % MOD;
46 }
47
48 void Deal()
49 {
50 int d = 1, N = 0;
51 for(int i=1; i<=num; i++)
52 if(vis[i]) d = (s64)d * P[i] % MOD ,N++;
53 N = N & 1 ? MOD-1 : 1;
54 Ans = Ans + (s64)N % MOD * d % MOD * d % MOD * Calc((D+2) / d) % MOD,
55 Ans %= MOD;
56 }
57
58 void Dfs(int T)
59 {
60 if(T > num) {Deal(); return;}
61 vis[T] = 1; Dfs(T+1);
62 vis[T] = 0; Dfs(T+1);
63 }
64
65 int main()
66 {
67 cin>>A>>B>>D;
68 if(D & 1) {printf("0"); return 0;}
69 Factor(D + 2);
70 Dfs(1);
71 printf("%d", (s64)(A * A % MOD + B * B % MOD) % MOD * Ans % MOD);
72 }