BZOJ1041 [HAOI2008]圆上的整点

本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作。

 

 

本文作者:ljh2000
作者博客:http://www.cnblogs.com/ljh2000-jump/
转载请注明出处,侵权必究,保留最终解释权!

 

题目链接:BZOJ1041

正解:数学

解题报告:

  参考博客:http://www.cppblog.com/zxb/archive/2010/10/18/130330.html。

  讲的比较清楚,公式推导就不赘述了。

 

//It is made by ljh2000
//有志者,事竟成,破釜沉舟,百二秦关终属楚;苦心人,天不负,卧薪尝胆,三千越甲可吞吴。
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <complex>
#include <bitset>
using namespace std;
typedef long long LL;
typedef long double LB;
typedef complex<double> C;
const double pi = acos(-1);
LL r,d,ans,rr;
inline LL gcd(LL x,LL y){ if(y==0) return x; return gcd(y,x%y); }
inline int getint(){
    int w=0,q=0; char c=getchar(); while((c<'0'||c>'9') && c!='-') c=getchar();
    if(c=='-') q=1,c=getchar(); while (c>='0'&&c<='9') w=w*10+c-'0',c=getchar(); return q?-w:w;
}

inline void solve(LL x){
	LL u,v,lin;
	for(u=1;u*u<=x;u++) {
		lin=x-u*u;
		v=sqrt(lin);
		if(u>=v) break;//前提
		if(v*v==lin && gcd(u,v)==1/*!!!*/) 
			ans++;
	}
}

inline void work(){
	r=getint(); rr=r*2; ans=1;
	for(d=1;d*d<=rr;d++) {
		if(rr%d!=0) continue;//!!!
		solve(rr/d);
		if(d*d!=rr) solve(d);
	}
	cout<<ans*4;
}

int main()
{
    work();
    return 0;
}
//有志者,事竟成,破釜沉舟,百二秦关终属楚;苦心人,天不负,卧薪尝胆,三千越甲可吞吴。

  

posted @ 2017-03-10 12:07  ljh_2000  阅读(829)  评论(0编辑  收藏  举报