[HAOI2008]圆上的整点

本文介绍了一种计算给定圆周上整数坐标点数量的方法。通过枚举和数学运算,程序能准确计算出指定半径的圆周上整数点的数量。

题目描述

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

输入输出格式

输入格式:

r

输出格式:

整点个数

输入输出样例

输入样例#1:
4
输出样例#1:
4

说明

n<=2000 000 000

接下来枚举d,a

为什么要除d?

因为他们不互质,a*b是完全平方数≠a,b都是完全平方数

记住还要a*a,b*b互质

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<cmath>
 6 using namespace std;
 7 long long r,k,ans,p,q;
 8 int tot;
 9 long long ys[500001];
10 void Dvide(long long x)
11 {int i;
12   for (i=1;i<=sqrt(x);i++)
13     if (x%i==0)
14       {
15     if (i*i==x)
16       {
17         tot++;
18         ys[tot]=i;
19       }
20     else
21       {
22         tot++;
23         ys[tot]=i;
24         tot++;
25         ys[tot]=x/i;
26       }
27       }
28 }
29 long long GCD(long long a,long long b)
30 {
31   if (b==0)
32     return a;
33   return GCD(b,a%b);
34 }
35 int main()
36 {int i;
37   cin>>r;
38   Dvide(2*r);
39   for (i=1;i<=tot;i++)
40     {
41       for (p=1;p*p<(r/ys[i]);p++)
42     {
43       q=sqrt(2*r/ys[i]-p*p);
44       if (p*p+q*q==2*r/ys[i])
45         if (GCD(p*p,q*q)==1) ans++;
46     }
47     }
48   cout<<ans*4+4;
49 }

 

 

转载于:https://www.cnblogs.com/Y-E-T-I/p/7554192.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值