[BZOJ1041][HAOI2008]圆上的整点 数学

题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1041

数学xjb分析题。

大概就是推公式分析性质+乱搞。

这里有一个还不错的博客写的比较好懂:http://www.cppblog.com/zxb/archive/2010/10/18/130330.html

看起来是几何题然而是数论。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<cmath>
 5 using namespace std;
 6 typedef long long ll;
 7 int inline gcd(int a,int b){
 8     return !b?a:gcd(b,a%b);
 9 }
10 ll ans=1;
11 void solve(ll x){
12     ll sx=sqrt(x);
13     for(ll u=1;u<=sx;u++){
14         ll tmp=x-u*u,v=sqrt(tmp);
15         if(u<v){
16             if(v*v==tmp&&gcd(u,v)==1)
17                 ans++;
18         }
19         else return;
20     }
21 }
22 int main(){
23     ll R;
24     scanf("%d",&R);
25     R<<=1;
26     ll sR=sqrt(R);
27     for(ll d=1;d<=sR;d++){
28         if(R%d==0){
29             solve(d);
30             if(d*d!=R) solve(R/d);
31         }
32     }
33     printf("%lld\n",ans<<2);
34     return 0;
35 }

 

posted @ 2017-10-08 10:48  halfrot  阅读(177)  评论(0编辑  收藏  举报