BZOJ1041 [HAOI2008]圆上的整点

看的题解,感觉都不好说什么,,

但是据说这个题是某年河南省,一个人都没正解?

数学还是太弱,

感觉这个题还是通过数学推导,强行将枚举范围缩小缩小小。。。

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <cmath>
 4 #include <iostream>
 5 #include <algorithm>
 6 using namespace std;
 7 typedef long long LL;
 8 LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}
 9 LL sqr(LL x){return x*x;}
10 int ans;
11 void cal(LL x){
12     for(LL i = 1;i*i<x;++i){
13         LL y = x-i*i,z = sqrt(y);
14         if(z*z!=y)continue;
15         if(i>=z)continue;
16         if(gcd(i*i,y)==1)ans++;
17     }
18 }
19 int main()
20 {
21     LL n;cin>>n;n*=2;
22     ans = 0;
23     for(LL i = 1;i*i<=n;++i){
24         if(i*i==n){cal(i);continue;}
25         if(n%i==0){
26             cal(i);cal(n/i);
27         }
28     }
29     cout<<(ans+1)*4<<endl;
30     return 0;
31 }

 

posted on 2015-08-17 01:41  round_0  阅读(134)  评论(0编辑  收藏  举报

导航