import fractions
target=10**7
mod=1000000007
f=[1]
for k in range(1,2*target+1):
f.append((f[-1]*k)%mod)
g=[1]*(2*target+1)
g[-1]=pow(f[2*target],mod-2,mod)
for k in range(2*target,1,-1):
g[k-1]=(g[k]*k)%mod
p=[]
for m in range(2,2000):
for n in range(1,m):
u,v=m*m-n*n,2*m*n
if fractions.gcd(u,v)==1:
a,b=u,v
while a*a<=target and b*b<=target:
p.append((a*a,b*b))
p.append((b*b,a*a))
a+=u
b+=v
p.sort()
s=f[2*target]*g[target]*g[target]
d=[0]*(len(p)+1)
for k,(x0,y0) in enumerate(p):
d[k]=(f[x0+y0]*g[x0]*g[y0])%mod
for j in range(k):
x1,y1=p[j][0],p[j][1]
if y1<=y0:
d[k]=(d[k]-d[j]*f[x0-x1+y0-y1]*g[x0-x1]*g[y0-y1])%mod
s-=d[k]*f[2*target-x0-y0]*g[target-x0]*g[target-y0]
print s%mod