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 ...
随机推荐
- oracle6
转换函数 介绍 转换函数用于将数据类型从一种转为另外一种.在某些情况下,oracle server允许值的数据类型和实际的不一样,这时oracle server会隐含的转化数据类型 比如: crea ...
- hadoop错误DataXceiver error processing WRITE_BLOCK operation
错误: DataXceiver error processing WRITE_BLOCK operation 原因: 文件操作超租期,实际上就是data stream操作过程中文件被删掉了. ...
- apache kafka技术分享系列(目录索引)--转载
原文地址:http://blog.csdn.net/lizhitao/article/details/39499283 kafka开发与管理: 1)apache kafka消息服务 2)kafak安装 ...
- RedHat7安装Tomcat
编译安装Tomcat 下载jdk (http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.htm ...
- Mybaitis配置总结
在mybatis-config.xml中配置分页插件,插件配置必须放在mapper前面 <plugins> <plugin interceptor="com.rrtong. ...
- 配置SSH免密码验证
为了防止无良网站的爬虫抓取文章,特此标识,转载请注明文章出处.LaplaceDemon/ShiJiaqi. http://www.cnblogs.com/shijiaqi1066/p/5183803. ...
- ui-router的使用
使用时需要ui中用ui-view指令指定 如: <div ui-view></div> 首先配置注册 ui-route var mainModule = angular.mod ...
- 滚动效果,marquee便签
语法: <marquee></marquee> 例子: <marquee><font size=+3 color=red>Hello, World< ...
- [功能帮助类] C# BaseRandom随机数,随机字符,可限制范围-帮助类 (转载)
点击下载 BaseRandom.rar 主要功能如下 .产生随机字符 .产生随机数 .在一定范围内产生随机数 看下面代码吧 /// <summary> /// 编 码 人:苏飞 /// 联 ...
- 数据库(学习整理)----1--如何彻底清除系统中Oracle的痕迹(重装Oracle时)
1.关于重装Oracle数据库: 由于以前装过Oracle数据库,但是版本不怎么样,结果过了试用期之后,我就没有破解和再找合适的版本了!直接使用电脑管家卸载了!可想而知,肯定没清除Oracle痕迹啊! ...