x^2+y^2=r^2
y^2=(r-x)(r+x)
1.设d=gcd(r-x,r+x)
2.设A=(r-x)/d,B=(r+x)/d;
因为y^2=A*B*d*d
所以A*B是完全平方数
又因为A,B互质
所以A,B是完全平方数
3.设A=a*a,B=b*b
所以y=a*d*b
x=(b^2-a^2)*d/2
r=(b^2+a^2)*d/2
#include<bits/stdc++.h> #define re return #define inc(i,l,r) for(long long i=l;i<=r;++i) using namespace std; template<typename T>inline void rd(T&x) { char c;bool f=0; while((c=getchar())<'0'||c>'9')if(c=='-')f=1; x=c^48; while((c=getchar())>='0'&&c<='9')x=x*10+(c^48); if(f)x=-x; } #define ll long long ll r,x,y,a,b,d,ans,r2; inline ll gcd(ll a,ll b){re b?gcd(b,a%b):a;} int main() { rd(r); r2=r*2; //inc(i,1,sqrt(r)) for(d=1;d<=sqrt(r2);++d) if(r2%d==0) { ll d1=r2/d; for(b=1;b<=sqrt(d);++b) { a=sqrt(d-b*b); if(b<=a||a==0)continue; if((a*a==d-b*b)&&gcd(a,b)==1)++ans; } if(d!=d1) { for(b=1;b<=sqrt(d1);++b) { a=sqrt(d1-b*b); if(b<=a||a==0)continue; if((a*a==d1-b*b)&&gcd(a,b)==1)++ans; } } } printf("%lld",(ans+1)*4); re 0; }