可惜没如果=_=
时光的河入海流

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 }

 

posted on 2017-10-22 11:50  珍珠鸟  阅读(342)  评论(0编辑  收藏  举报