感谢http://hzwer.com/1457.html
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; long long r,ans=0; long long gcd(long long a,long long b) { if (b==0) return a; else return gcd(b,a%b); } bool check(long long a,long long r) { long long b=sqrt(r-a*a); if ((a*a+b*b==r) && (gcd(a,b)==1) && (b!=0) && (a<b)) return true; return false; } int main() { scanf("%lld",&r); for (long long d=1;d<=sqrt(2*r);d++) { if (2*r%d==0) { for (long long i=1;i<=sqrt(2*r/d);i++) if (check(i,2*r/d)) ans++; if (d!=(2*r)/d) { for (long long i=1;i<=sqrt(d);i++) if (check(i,d)) ans++; } } } printf("%lld\n",ans*4+4); return 0; }