题目概述
给出
r
,求
解题报告
之前知道一个枚举勾股数的公式 (2ab)2+(a2−b2)2=(a2+b2)2 ,但是这货并不能枚举完所有勾股数,WTF?
示例程序
#include<cstdio>
#include<cmath>
using namespace std;
typedef double DB;typedef long long LL;
LL R,ans;
inline bool check(LL x) {return fabs(sqrt(x)-(LL)sqrt(x))<1e-10;}
LL gcd(LL a,LL b) {if (!b) return a;return gcd(b,a%b);}
int main()
{
freopen("program.in","r",stdin);
freopen("program.out","w",stdout);
scanf("%lld",&R);
for (LL i=1;i*i<=(R<<1);i++) if ((R<<1)%i==0)
{
LL now=i;
for (LL A=1;A*A<=R/now;A++)
{
LL B=(R<<1)/now-A*A;if (B<=A*A||!check(B)) continue;
ans+=gcd(A*A,B)==1;
}
if (i*i==(R<<1)) break;now=(R<<1)/now;
for (LL A=1;A*A<=R/now;A++)
{
LL B=(R<<1)/now-A*A;if (B<=A*A||!check(B)) continue;
ans+=gcd(A*A,B)==1;
}
}
return printf("%lld\n",ans+1<<2),0;
}