Problem:
Score : 1000 points

Problem Statement

In a two-dimensional plane, we have a rectangle R whose vertices are (0,0), (W,0), (0,H), and (W,H), where W and H are positive integers.
Here, find the number of triangles \Delta in the plane that satisfy all of the following conditions:

Each vertex of \Delta is a grid point, that is, has integer x- and y-coordinates.

\Delta and R shares no vertex.

Each vertex of \Delta lies on the perimeter of R, and all the vertices belong to different sides of R.

\Delta contains at most K grid points strictly within itself (excluding its perimeter and vertices).

Constraints

1 \leq W \leq 10^5

1 \leq H \leq 10^5

0 \leq K \leq 10^5

Input

Input is given from Standard Input in the following format:

W H K

Output

Print the answer.

Sample Input 1

2 3 1

Sample Output 1

12

For example, the triangle with the vertices (1,0), (0,2), and (2,2) contains just one grid point within itself and thus satisfies the condition.

Sample Input 2

5 4 5

Sample Output 2

132

Sample Input 3

100 100 1000

Sample Output 3

461316

Solution in C++ (GCC 9.2.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int H,W,K;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W>>K;
	ll ret=0;
	FOR(i,2) {
		for(int s=0;s<=H-2;s++) {
			int R=2*K+__gcd(s,W)-2;
			ll pat=0;
			for(x=1;x<W;x++) {
				int R2=R-s*x;
				if(R2<0) break;
				
				int Ymi=R2/W;
				//if(Ymi) pat+=Ymi-1;
				for(y=max(1,Ymi);y<=Ymi+2 && y+s<H;y++) {
				//for(y=1;y<=Ymi+2 && y+s<H;y++) {
					ll v=1LL*W*y-__gcd(x,y)-__gcd(W-x,y+s);
					if(v<=R2) pat++;
				}
				
			}
			ret+=((s==0)?1:2)*pat;
		}
		swap(H,W);
	}
	cout<<2*ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}