这个题一开始看着没什么思路,但是一看题解就明白了不少,主要是数学证明,代码很好写。

贴个网址:

hzwer

题干:

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

输入格式
  只有一个正整数n,n<=2000 000 000

输出格式
  整点个数

样例输入
4
样例输出
4

代码:

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
    int n,ans=4;
    scanf("%d",&n);
    while((n&1)^1) n>>=1;
    int x=1;
    while(x*x<=n) x++;
    for(int i=2; i<=x; i++)
        if(n%i==0)
        {
            int c=0;
            while(n%i==0) c+=2,n/=i;
            if(i%4==1) ans*=(c+1);
        }
    if(n>1&&n%4==1) ans*=3;
    printf("%d\n",ans);
    return 0;
}

 

相关文章:

  • 2022-02-05
  • 2022-12-23
  • 2021-09-21
  • 2021-05-30
  • 2022-01-14
猜你喜欢
  • 2022-03-09
  • 2021-09-24
  • 2021-10-19
  • 2021-11-11
相关资源
相似解决方案