BZOJ-1041: [HAOI2008]圆上的整点 (数学神推理)

1041: [HAOI2008]圆上的整点

Time Limit: 10 Sec  Memory Limit: 162 MB
Submit: 4565  Solved: 2049
[Submit][Status][Discuss]

Description

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

Input

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

Output

整点个数

Sample Input

4

Sample Output

4

HINT

Source

Orz hzwer 其实这题的推理过程并不难理解,然鹅就是想不到哇 _(:зゝ∠)_

附自己手推的过程 _(:зゝ∠)_ 字丑不要介意 _(:зゝ∠)_

对了补充一下第三版里面的a的范围求粗来之后就从1~limit(a) 枚举a了

 1 #include "bits/stdc++.h"
 2 using namespace std;
 3 typedef long long LL;
 4 LL r,ans;
 5 LL gcd(LL x,LL y){return (y==0?x:gcd(y,x%y));}
 6 bool check(LL y,double x){
 7     if (x==floor(x)){
 8         LL x1=(LL)floor(x);
 9         if (gcd(x1*x1,y*y)==1 && x1*x1!=y*y)
10             return true;
11     }
12     return false;
13 }
14 int main(){
15     freopen ("point.in","r",stdin);freopen ("point.out","w",stdout);
16     int i,j;
17     scanf("%lld",&r);
18     LL d,a;double b;
19     for (d=1;d*d<=2*r;d++){
20         if ((2*r)%d==0){
21             for (a=1;a*a<=(2*r/(2*d));a++){
22                 b=sqrt(2*r*1.0/(d*1.0)-a*a);
23                 if (check(a,b))
24                     ans++;
25             }
26             if (d!=(2*r/d)){
27                 for (a=1;a*a<=(d/2);a++){
28                     b=sqrt(d*1.0-a*1.0*a*1.0);
29                     if (check(a,b)) ans++;
30                 }
31             }
32         }
33     }
34     printf("%lld",ans*4+4);
35     return 0;
36 }

 

转载于:https://www.cnblogs.com/keximeiruguo/p/7708981.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值