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
#include <bits/stdc++.h>
using namespace std;

#define st first
#define nd second

typedef long long int lli;
typedef pair<lli, lli> pkt;

const int MAXK = 300;
const int MAX = 600;

vector<pkt> bok;

int isSq[2*MAXK*MAXK+10];

pkt operator+(pkt a, pkt b) {
	a.st += b.st;
	a.nd += b.nd;
	return a;
}

lli mod(pkt a) {
	return isSq[a.st*a.st+a.nd*a.nd];
}

bool cmp(const pkt &a, const pkt &b) {
	return a.st*b.nd-a.nd*b.st < 0;
}

unsigned np[MAX][MAX];

unsigned npk(lli n, lli k) {
	if (n < 0 || k < 0 || k > n)
		return 0;
	
	return np[n][k];
}

int main() {
	lli x, y, k;
	scanf("%lld%lld%lld", &x, &y, &k);
	
// 	// npk
// 	for (int i=0; i<500+5; i++) {
// 		np[i][0] = 1;
// 		for (int j=1; j<=i; j++) {
// 			np[i][j] = np[i-1][j-1]+np[i-1][j];
// 		}
// 	}
	
	
	
	for (int i=0; i<MAXK; i++)
		isSq[i*i] = i;
	
	for (int i=-k; i<=0; i++) {
		for (int j=-k; j<=k; j++) {
			if (i == 0 && j == 0)
				break;
			int tmp = isSq[i*i+j*j];
			if (tmp > 0 && tmp <= k && __gcd(abs(i), abs(j)) == 1)
				bok.push_back({i,j});
		}
	}
	
	sort(bok.begin(), bok.end(), cmp);
	int n = bok.size();
	
	for (int i=0; i<n; i++) {
		bok.push_back({-bok[i].st, -bok[i].nd});
	}
	
// 	printf("%d\n", (int)bok.size());
	n = bok.size();
	
// 	for (int i=0; i<n; i++)
// 		printf(" %lld %lld\n", bok[i].st, bok[i].nd);
	unsigned res = 0;
	
	for (int mas=0; mas<(1<<(bok.size())); mas++) {
		if (__builtin_popcount(mas) < 3)
			continue;
		
		vector<pkt> a;
		a.push_back({0,0});
		lli eminx=0, eminy=0, emaxx=0, emaxy=0;
		for (int i=0; i<n; i++) {
			if (mas&(1<<i)) {
				a.push_back(a.back()+bok[i]);
				eminx = min(eminx, a.back().st);
				eminy = min(eminy, a.back().nd);
				emaxx = max(emaxx, a.back().st);
				emaxy = max(emaxy, a.back().nd);
			}
		}
		
		if (a.back().st != 0 || a.back().nd != 0)
			continue;
		
		if ((x-(emaxx-eminx)) < 0 || (y-(emaxy-eminy)) < 0)
			continue;
		
		res += (x-(emaxx-eminx))*(y-(emaxy-eminy));
	}
	
	printf("%u\n", res);
	
	return 0;
}