Language: C++

#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

int w,h,k;
inline ll solve(int w,int h,int k){
	ll ans=0;
	/*FOR(y,1,w)
		FOR(z,1,h)
			For(x,1,z) if (1ll*y*z+1ll*x*(w-y)-__gcd(x,y)-__gcd(w-y,z)-__gcd(w,z-x)<=2*k-2){
				ans++;
				printf("%d %d %d %d\n",w,y,z,x);
				if (z!=x) ans++;
			}
	return ans;*/
	//ll sum=0;
	FOR(y,1,w){
		++ans;
		For(z,2,h-1){
			if (1ll*y*z+1ll*z*(w-y)-__gcd(z,y)-__gcd(w-y,z)-w<=2*k-2) ++ans;
			int l=1,r=z-1,tmp=__gcd(w-y,z),L=0,R=0,lim=2*k-2;
			l=1,r=z-1;
			while (l<=r){
				int mid=l+r>>1;
				if (1ll*y*z+1ll*(w-y)*mid-y-min(z-mid,w)-tmp<=lim) R=mid,l=mid+1;
					else r=mid-1;
			}
			if (R==0) break;
			//sum+=R-L;
			int ret=0;
			For(x,1,R) if (1ll*y*z+1ll*(w-y)*x-tmp-__gcd(x,y)-__gcd(w,z-x)<=lim){
				ret+=2;
			}
			ans+=ret;
		}
	}
	return ans;
}

int main(){
	w=read(),h=read(),k=read();
	if (w==1||h==1) return puts("0"),0;
	printf("%lld\n",2*(solve(w,h,k)+solve(h,w,k)));
}#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

int w,h,k;
inline ll solve(int w,int h,int k){
	ll ans=0;
	/*FOR(y,1,w)
		FOR(z,1,h)
			For(x,1,z) if (1ll*y*z+1ll*x*(w-y)-__gcd(x,y)-__gcd(w-y,z)-__gcd(w,z-x)<=2*k-2){
				ans++;
				printf("%d %d %d %d\n",w,y,z,x);
				if (z!=x) ans++;
			}
	return ans;*/
	//ll sum=0;
	FOR(y,1,w){
		++ans;
		For(z,2,h-1){
			if (1ll*y*z+1ll*z*(w-y)-__gcd(z,y)-__gcd(w-y,z)-w<=2*k-2) ++ans;
			int l=1,r=z-1,tmp=__gcd(w-y,z),L=0,R=0,lim=2*k-2;
			l=1,r=z-1;
			while (l<=r){
				int mid=l+r>>1;
				if (1ll*y*z+1ll*(w-y)*mid-y-min(z-mid,w)-tmp<=lim) R=mid,l=mid+1;
					else r=mid-1;
			}
			if (R==0) break;
			//sum+=R-L;
			int ret=0;
			For(x,1,R) if (1ll*y*z+1ll*(w-y)*x-tmp-__gcd(x,y)-__gcd(w,z-x)<=lim){
				ret+=2;
			}
			ans+=ret;
		}
	}
	return ans;
}

int main(){
	w=read(),h=read(),k=read();
	if (w==1||h==1) return puts("0"),0;
	printf("%lld\n",2*(solve(w,h,k)+solve(h,w,k)));
}

Compiler output:
a.cc:67:2: error: stray '#' in program
   67 | }#include<bits/stdc++.h>
      |  ^
a.cc: In function 'll solve(int, int, int)':
a.cc:40:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   40 |         FOR(y,1,w){
      |             ^
a.cc:3:38: note: in definition of macro 'FOR'
    3 | #define FOR(i,x,y) for (register int i=(x);i<(y);i++)
      |                                      ^
a.cc:42:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   42 |                 For(z,2,h-1){
      |                     ^
a.cc:2:38: note: in definition of macro 'For'
    2 | #define For(i,x,y) for (register int i=(x);i<=(y);i++)
      |                                      ^
a.cc:54:29: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   54 |                         For(x,1,R) if (1ll*y*z+1ll*(w-y)*x-tmp-__gcd(x,y)-__gcd(w,z-x)<=lim){
      |                             ^
a.cc:2:38: note: in definition of macro 'For'
    2 | #define For(i,x,y) for (register int i=(x);i<=(y);i++)
      |                                      ^
a.cc: At global scope:
a.cc:67:3: error: 'include' does not name a type
   67 | }#include<bits/stdc++.h>
      |   ^~~~~~~
a.cc:86:11: error: redefinition of 'll read()'
   86 | inline ll read(){
      |           ^~~~
a.cc:20:11: note: 'll read()' previously defined here
   20 | inline ll read(){
      |           ^~~~
a.cc:94:5: error: redefinition of 'int w'
   94 | int w,h,k;
      |     ^
a.cc:28:5: note: 'int w' previously declared here
   28 | int w,h,k;
      |     ^
a.cc:94:7: error: redefinition of 'int h'
   94 | int w,h,k;
      |       ^
a.cc:28:7: note: 'int h' previously declared here
   28 | int w,h,k;
      |       ^
a.cc:94:9: error: redefinition of 'int k'
   94 | int w,h,k;
      |         ^
a.cc:28:9: note: 'int k' previously declared here
   28 | int w,h,k;
      |         ^
a.cc:95:11: error: redefinition of 'll solve(int, int, int)'
   95 | inline ll solve(int w,int h,int k){
      |           ^~~~~
a.cc:29:11: note: 'll solve(int, int, int)' previously defined here
   29 | inline ll solve(int w,int h,int k){
      |           ^~~~~
a.cc: In function 'll solve(int, int, int)':
a.cc:106:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  106 |         FOR(y,1,w){
      |             ^
a.cc:69:38: note: in definition of macro 'FOR'
   69 | #define FOR(i,x,y) for (register int i=(x);i<(y);i++)
      |                                      ^
a.cc:108:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  108 |                 For(z,2,h-1){
      |                     ^
a.cc:68:38: note: in definition of macro 'For'
   68 | #define For(i,x,y) for (register int i=(x);i<=(y);i++)
      |                                      ^
a.cc:120:29: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  120 |                         For(x,1,R) if (1ll*y*z+1ll*(w-y)*x-tmp-__gcd(x,y)-__gcd(w,z-x)<=lim){
      |                             ^
a.cc:68:38: note: in definition of macro 'For'
   68 | #define For(i,x,y) for (register int i=(x);i<=(y);i++)
      |                                      ^
a.cc: At global scope:
a.cc:129:5: error: redefinition of 'int main()'
  129 | int main(){
      |     ^~~~
a.cc:63:5: note: 'int main()' previously defined here
   63 | int main(){
      |     ^~~~