bzoj 1041: [HAOI2008]圆上的整点 本原勾股數組
1041: [HAOI2008]圆上的整点
Time Limit: 10 Sec Memory Limit: 162 MB
Submit: 2027 Solved: 853
[Submit][Status]
Description
求一个给定的圆(x^2+y^2=r^2),在圆周上有多少个点的坐标是整数。
Input
r
Output
整点个数
Sample Input
Sample Output
HINT
n<=2000 000 000
Source
這道題可用本原勾股數組解,由於本原勾股數組(x,y,z),x^2+y^2==z且gcd(x,y)==gcd(x,z)==gcd(y,z)==1可表示爲
x=a^2-b^2
y=2*a*bz=a^2+b^2
本題已知z,那麼我們可以先sqrt(n)枚舉n的因數z,再sqrt(z)枚舉a,統計即可。
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<string>
#include<queue>
using namespace std;
#ifdef WIN32
#define LL "%I64d"
#else
#define LL "%lld"
#endif
#define MAXN 1100
#define MAXV MAXN*2
#define MAXE MAXV*2
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
typedef long long qword;
inline int nextInt()
{
char ch;
int x=;
bool flag=false;
do
ch=getchar(),flag=(ch=='-')?true:flag;
while(ch<''||ch>'');
do x=x*+ch-'';
while (ch=getchar(),ch<='' && ch>='');
return x*(flag?-:);
} qword n,m,nn;
qword gcd(qword x,qword y)
{
return (x%y==)?y:gcd(y,x%y);
}
int count(qword n)
{
qword x,y;
if (n==)
{
// cout<<"0 "<<nn<<endl;
return ;
}
qword l=ceil(sqrt(n));
int ans=;
for (x=;x<l;x++)
{
y=sqrt(n-x*x);
if (x*x+y*y!=n)continue;
if (x>=y)break;
if (gcd(y*y-x*x,*y*y)!=)continue;
// cout<<(y*y-x*x)*(nn/n)<<" "<<2*x*y*(nn/n)<<endl;
// cout<<2*x*y*(nn/n)<<" "<<(y*y-x*x)*(nn/n)<<endl;
ans+=+(x&&y);
}
return ans*;
}
int main()
{
freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int i,j,k;
int x,y,z;
scanf(LL,&n);
nn=n;
qword ans=;
qword l=ceil(sqrt(n));
for (i=;i<l;i++)
{
if (n%i==)
{
ans+=count(i);
ans+=count(n/i);
}
}
if (l*l==n)ans+=count(l);
printf(LL"\n",ans);
return ;
}
bzoj 1041: [HAOI2008]圆上的整点 本原勾股數組的更多相关文章
- BZOJ 1041: [HAOI2008]圆上的整点
1041: [HAOI2008]圆上的整点 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 3621 Solved: 1605[Submit][Sta ...
- bzoj 1041: [HAOI2008]圆上的整点 数学
1041: [HAOI2008]圆上的整点 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/ ...
- BZOJ 1041: [HAOI2008]圆上的整点【数论,解方程】
1041: [HAOI2008]圆上的整点 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 4210 Solved: 1908[Submit][Sta ...
- BZOJ 1041 [HAOI2008]圆上的整点:数学
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1041 题意: 给定n(n <= 2*10^9),问你在圆x^2 + y^2 = n^ ...
- BZOJ 1041 [HAOI2008]圆上的整点:数学【费马平方和定理】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1041 题意: 给定n(n <= 2*10^9),问你在圆x^2 + y^2 = n^ ...
- BZOJ(2) 1041: [HAOI2008]圆上的整点
1041: [HAOI2008]圆上的整点 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 4966 Solved: 2258[Submit][Sta ...
- 1041: [HAOI2008]圆上的整点
1041: [HAOI2008]圆上的整点 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 4298 Solved: 1944[Submit][Sta ...
- 【BZOJ】1041: [HAOI2008]圆上的整点(几何)
http://www.lydsy.com:808/JudgeOnline/problem.php?id=1041 所谓的神题,我不会,直接题解..看了半天看懂题解了.详见hzwer博客 这题呢,我只能 ...
- 1041: [HAOI2008]圆上的整点 - BZOJ
Description 求一个给定的圆(x^2+y^2=r^2),在圆周上有多少个点的坐标是整数.Input rOutput 整点个数Sample Input4Sample Output4HINT n ...
随机推荐
- JavaScript读取txt文本文件方法详解
http://blog.163.com/sophie8910@126/blog/static/8304612620122834121264/ 第一步:创建一个可以将文件翻译成文件流的对象. Var f ...
- 跟我一步一步开发自己的Openfire插件
http://www.blogjava.net/hoojo/archive/2013/03/07/396146.html 跟我一步一步开发自己的Openfire插件 这篇是简单插件开发,下篇聊天记录插 ...
- XMPP协议实现原理介绍
本文介绍XMPP协议原理及相关信息. XMPP协议简介 XMPP(Extensible Messageing and Presence Protocol:可扩展消息与存在协议)是目前主流的四种IM ...
- 使用java进行文件编码转换
在开发过程中,可能会遇到文件编码的转换,尽管说开发工具eclipse能够转换编码,可是有的情况却非常不方便.比方,原来文件本身的编码是GBK,如今要转换成UTF-8,假设直接在eclipse中把文件编 ...
- Java中List和ArrayList的区别(转)
List是一个接口,而ListArray是一个类. ListArray继承并实现了List. 所以List不能被构造,但可以向上面那样为List创建一个引用,而ListArray就可以被构造. ...
- HDU 5046 Airport ( Dancing Links 反复覆盖 )
今年上海网络赛的一道题目 , 跟 HDU 2295 如出一辙 . 就是距离的计算一个是欧几里得距离 , 一个是曼哈顿距离 学完DLX感觉这题好水 ,就是一个裸的反复覆盖 注意下别溢出即可了 #incl ...
- verview of Spring Framework--转
http://docs.spring.io/spring/docs/current/spring-framework-reference/html/overview.html 2. Introduct ...
- HDU2088JAVA
Hot~~招聘——巴卡斯(杭州),亚信科技,壹晨仟阳(杭州) Box of Bricks Time Limit: 1000/1000 MS (Java/Others) Memory Limit: ...
- C#实现动态网站伪静态,使seo更友好
本教程将使用Visual Studio 2013手把手教你实现webform动态页面的伪静态.本教程配套的C#源码工程可通过我的github下载.地址:https://github.com/shell ...
- 用bootstrap的tab插件做一个图层切换效果(感觉会误导淫们,大家当乐子看吧)
小伙伴们啊,我JS真的是个渣渣,所以总想要偷懒,于是为了实现效果就把tab插件给改了(各位大神轻拍啊,我是小白,很纯洁滴,小心脏也很脆弱)…… 最近做的项目为了考虑以后的移动设备兼容性,所以用了Boo ...