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
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#include <bits/stdc++.h>                                                        
using namespace std;                                                            
typedef double ld;                                                          
typedef long long ll;                                                           
typedef pair<int, int> Pii;                                                     
typedef vector<Pii> vpii;                                                       
typedef vector<int> vi;
typedef vector<vi> vvi;                                                         
typedef vector<ll> vll;                                                         
#define pb push_back                                                            
#define fst first                                                               
#define snd second
int X, Y, K;
bool sq[250 * 250 + 1];
vpii gen()
{
	for(int i = 1; i <= 250; ++i)
		sq[i * i] = true;
	vpii res = {{0,1}};
	for(int i = 1; i <= K; ++i)
		for(int j = 1; j <= K; ++j)
		{
			int sum = i * i + j * j;
			if(__gcd(i,j) == 1 && sum <= K * K && sq[sum])
				res.pb({i,j});
		}
	return res;
}
vpii gen2(vpii klocki)
{
	vpii klocki_cal = klocki;
	for(Pii p : klocki)
		klocki_cal.pb({p.snd, -p.fst});
	for(Pii p : klocki)
		klocki_cal.pb({-p.fst, -p.snd});
	for(Pii p : klocki)
		klocki_cal.pb({-p.snd, p.fst});
	return klocki_cal;
}
Pii up(Pii p, int x)
{
	return {min(p.fst, x), max(p.snd, x)};
}
void subtask1()
{
	vpii klocki = gen();
	vpii klocki_cal = gen2(klocki);
	int res = 0;
	int lim = klocki_cal.size();
	for(int m = 0; m < (1 << lim); ++m)
	{
		if(__builtin_popcount(m) > 2)
		{
			Pii p1(0,0), p2(0,0);
			int s1 = 0, s2 = 0;
			for(int i = 0; i < lim; ++i)
				if((m >> i) & 1)
				{
					s1 += klocki_cal[i].fst;
					s2 += klocki_cal[i].snd;
					p1 = up(p1, s1);
					p2 = up(p2, s2);
				}
			if(s1 == 0 && s2 == 0)
			{
				s1 = p1.snd - p1.fst;
				s2 = p2.snd - p2.fst;
				if(s1 < X && s2 < Y)
				{
					res += (X - s1) * (Y - s2);
				}
			}
		}
	}
	printf("%u\n", (unsigned) res);
}
int T[200][200];
int T2[200][200];
void przesun(Pii p)
{
	for(int j = 0; j < X; ++j)
	for(int k = 0; k < Y; ++k)
	{
		T2[j][k] = T[j][k];
		if(j - p.fst >= 0 && j - p.fst < X)
		if(k - p.snd >= 0 && k - p.snd < Y)
			T2[j][k] += T[j-p.fst][k-p.snd];
	}
	
	for(int i = 0; i < X; ++i)
	for(int j = 0; j < Y; ++j)
		T[i][j] = T2[i][j];
}
void subtask2()
{
	vpii male = gen();
	vpii klocki = gen2(male);
	int sz = male.size() * 2;
	vpii klocki1;
	vpii klocki2;
	for(int i = 0; i < sz; ++i)
		klocki1.pb(klocki[i]);
	for(int i = 0; i < sz; ++i)
		klocki2.pb(klocki[i+sz]);
	int res = 0;
	
	for(int i = 0; i < Y; ++i)
	{
		for(int j = 0; j < X; ++j)
			for(int k = 0; k < Y; ++k)
				T[j][k] = 0;
		T[0][i] = 1;
		for(Pii p : klocki1)
			przesun(p);
		
		for(int j = 0; j < X; ++j)
			for(int k = 0; k < Y; ++k)
				T[j][k] *= (X - j);
		for(Pii p : klocki2)
			przesun(p);
		res += T[0][i];
	}
	res -= X * Y;
	for(Pii p : klocki1)
	{
		if(abs(p.fst) < X && abs(p.snd) < Y)
			res -= (X - abs(p.fst)) * (Y - abs(p.snd));
	}
	printf("%u\n", (unsigned) res);
}


void real_subtask3()
{
	vi ky = {1, 5, 13, 17, 25, 29, 37, 41, 53, 61, 65, 73, 85, 89, 97, 101, 109, 113, 125, 137, 145, 149, 157, 169, 173, 181, 185, 193, 197, 205, 221, 229, 233, 241};
	vvi wektorek = {{1, 1, 1, 1},
{73, 585, 585, 5316},
{1829, 45031, 45031, 1214188},
{133089, 6322345, 6322345, 316484604},
{11993245, 941471067, 941471067, -872850676},
{1535638041, -1174845319, -1174845319, -165356068},
{547682309, 994795395, 994795395, -1519327352},
{-729309151, 1747674161, 1747674161, 2045608656},
{-998866723, 1737252415, 1737252415, -567084048},
{2140219417, 609747729, 609747729, 425724720},
{-908975023, -595447391, -595447391, -1055227968},
{-452303955, 437712451, 437712451, 1455219800},
{-743256091, 211044991, 211044991, 1566289608},
{1690965681, -1016008439, -1016008439, 60391644},
{1096062349, -758405929, -758405929, 2044903956},
{1654251977, 698667385, 698667385, -970846316},
{-454234459, 2058969451, 2058969451, 1791013532},
{-1387909855, 1625950525, 1625950525, -1903301156},
{-825949603, 1413599627, 1413599627, 473620188},
{2032222553, 729907001, 729907001, 1424717084},
{-779469551, -1371207607, -1371207607, -1412625844},
{-1281204627, -1871092917, -1871092917, 854782324},
{-1771438375, 1924356657, 1924356657, -894185888},
{319093637, 846438283, 846438283, 267154732},
{-1953229727, -1196620839, -1196620839, 1817087796},
{-467604563, 1786444163, 1786444163, 1617219512},
{-1110795275, 896225303, 896225303, 1284425036},
{1483982033, 554882473, 554882473, 377641604},
{-1922218051, -879112013, -879112013, 1214744112},
{1914047029, 1075271827, 1075271827, -1721588208},
{-46010563, 1886128043, 1886128043, -879393420},
{902879417, 1278208009, 1278208009, 1421610980},
{-489345675, -214721849, -214721849, 855458420},
{1039346929, 1409062405, 1409062405, 395262900}};
	int ind = ky.size();
	--ind;
	while(ky[ind] > K) --ind;
	vi wsp = wektorek[ind];
	int xy = X * Y;
	int total = wsp[0];
	int a = wsp[1];
	int b = wsp[2];
	int ab = wsp[3];
	int res = total * xy - a * Y - b * X + ab;
	printf("%u\n", (unsigned) res);
}
int main()
{
	scanf("%d%d%d", &X, &Y, &K);
	if(K <= 15)
	{
		subtask1(); // done
	}
	else if(X <= 150 && Y <= 150)
	{
		subtask2(); // done
	}
	else if(X >= 10000 && Y >= 10000)
	{
		real_subtask3();
	}
	else
	{
		real_subtask3();
		//tego nie umiem :/
	}
}