Description
求一個給定的圓,在圓周上有多少個點的座標是整數。
Input
只有一個正整數
Output
整點個數
Sample Input
4
Sample Output
4
首先不難看出最終答案是第一象限的整點數乘4加上四個座標軸上的點。
所以假設。
移項,得到
關鍵一步: 設,,則互質。
代入,得到,。
因爲,所以
兩式相減有,即
兩式相加有,所以。
不妨設,由得。
枚舉,然後求出,然後判和即可qwq
毒瘤代碼
#include<stdio.h>
#include<cstring>
#include<algorithm>
#include<math.h>
#define re register int
#define rl register ll
using namespace std;
typedef long long ll;
int read() {
re x=0,f=1;
char ch=getchar();
while(ch<'0' || ch>'9') {
if(ch=='-') f=-1;
ch=getchar();
}
while(ch>='0' && ch<='9') {
x=(x<<1)+(x<<3)+ch-'0';
ch=getchar();
}
return x*f;
}
const int Size=10005;
const int INF=0x3f3f3f3f;
ll n,t,num[Size];
int main() {
n=read();
int tot=0;
ll sn=sqrt(t=(n<<1));
//先對2n分解質因數
for(re i=1; i<sn; i++) {
if(t%i==0) {
num[++tot]=i;
num[++tot]=t/i;
}
}
if(t%sn==0) num[++tot]=sn;
int ans=0;
for(re i=1; i<=tot; i++) {
ll d=num[i],maxa=n/d;
for(rl a=1; a*a<maxa; a++) {
ll b=sqrt(t/d-a*a);
if(__gcd(a,b)==1 && d*(a*a+b*b)==t) {
ans++;
}
}
}
printf("%d",(ans<<2)+4);
return 0;
}