BZOJ1041:[HAOI2008]圆上的整点(数论)

Description

求一个给定的圆(x^2+y^2=r^2),在圆周上有多少个点的坐标是整数。

Input

只有一个正整数n,n<=2000 000 000

Output

整点个数

Sample Input

4

Sample Output

4

Solution

一个有趣的视频

Code

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 #include<cmath>
 5 #define LL long long
 6 using namespace std;
 7 LL n,ans=1;
 8 int main()
 9 {
10     scanf("%lld",&n); n=n*n;
11     for (int i=2; i<=sqrt(n); ++i)
12     {
13         int cnt=0;
14         while (n%i==0) n/=i, cnt++;
15         if (i%4==3) ans*=(cnt%2)?0:1;
16         else if (i%4==1) ans*=cnt+1;
17     }
18     if (n%4==3) ans=0;
19     else if (n!=1 && n%4==1) ans*=2;
20     printf("%lld\n",ans*4);
21 }
posted @ 2019-03-02 17:31  Refun  阅读(180)  评论(0编辑  收藏  举报