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

4

Sample Output

4

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*b

  z=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]圆上的整点 本原勾股數組的更多相关文章

  1. BZOJ 1041: [HAOI2008]圆上的整点

    1041: [HAOI2008]圆上的整点 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 3621  Solved: 1605[Submit][Sta ...

  2. bzoj 1041: [HAOI2008]圆上的整点 数学

    1041: [HAOI2008]圆上的整点 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/ ...

  3. BZOJ 1041: [HAOI2008]圆上的整点【数论,解方程】

    1041: [HAOI2008]圆上的整点 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 4210  Solved: 1908[Submit][Sta ...

  4. BZOJ 1041 [HAOI2008]圆上的整点:数学

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1041 题意: 给定n(n <= 2*10^9),问你在圆x^2 + y^2 = n^ ...

  5. BZOJ 1041 [HAOI2008]圆上的整点:数学【费马平方和定理】

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1041 题意: 给定n(n <= 2*10^9),问你在圆x^2 + y^2 = n^ ...

  6. BZOJ(2) 1041: [HAOI2008]圆上的整点

    1041: [HAOI2008]圆上的整点 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 4966  Solved: 2258[Submit][Sta ...

  7. 1041: [HAOI2008]圆上的整点

    1041: [HAOI2008]圆上的整点 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 4298  Solved: 1944[Submit][Sta ...

  8. 【BZOJ】1041: [HAOI2008]圆上的整点(几何)

    http://www.lydsy.com:808/JudgeOnline/problem.php?id=1041 所谓的神题,我不会,直接题解..看了半天看懂题解了.详见hzwer博客 这题呢,我只能 ...

  9. 1041: [HAOI2008]圆上的整点 - BZOJ

    Description 求一个给定的圆(x^2+y^2=r^2),在圆周上有多少个点的坐标是整数.Input rOutput 整点个数Sample Input4Sample Output4HINT n ...

随机推荐

  1. 在 VS14 上安装 Visual F# Power Tools

    在 VS14 上安装 Visual F# Power Tools Visual F# Power Tools 眼下版本号 1.3,下载地址:http://visualstudiogallery.msd ...

  2. Java jdbc数据库连接池总结!(转)

    1. 引言 近年来,随着Internet/Intranet建网技术的飞速发展和在世界范围内的迅速普及,计算机 应用程序已从传统的桌面应用转到Web应用.基于B/S(Browser/Server)架构的 ...

  3. QuaZip实现多文件打包

    项目需求: 在Goldenfarm客户端中当用户选择了本地场景文件,并进行本地场景文件分析后会产生分析结果,分析结果主要包括:贴图纹理.可渲染层等,其中贴图纹理指出了在场景文件中使用到的贴图或其它文件 ...

  4. 让iOS开发变得更有效率-分类、工具类

    在工作中整理的一些分类与工具类,分享给大家.这些工具类可以减少项目中的代码量,让代码变得更简洁,可以大大的提升项目的效率,直接拖到项目中使用即可.下载地址:https://github.com/lee ...

  5. DevExpress的GridView设置特定行的样式

    GridView控件绑定事件: gridView_SampleData.CustomDrawCell += gridView_SampleData_CustomDrawCell; 根据自定义逻辑来改变 ...

  6. Nginx性能统计模块http_stub_status_module使用

    1.进入nginx源码目录,重新配置编译参数 ./configure --prefix=/usr/local/nginx/ --with-http_stub_status_module 2.重新编译安 ...

  7. PHP 根据值查找键名

    array_search (PHP 4 >= 4.0.5, PHP 5) mixed array_search ( mixed $needle , array $haystack [, bool ...

  8. 错误:Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80070005 拒绝访问。

    最近,把一个网站部署到另一个服务器上,网站中一个功能word转pdf报下面错误: 在此附上解决方案: 方法1:配置Web.Config文件,在每次请求时模拟本地系统的账户. 具体操作:在Web.Con ...

  9. [Excel] C# ExcelHelper操作类 (转载)

    点击下载 ExcelHelper.rar 主要功能如下1.导出Excel文件,自动返回可下载的文件流 2.导出Excel文件,转换为可读模式3.导出Excel文件,并自定义文件名4.将数据导出至Exc ...

  10. 从腾讯QQgame高性能服务器集群架构看“分而治之”与“自治”等分布式架构设计原则

    转载:http://space.itpub.net/17007506/viewspace-616852 腾讯QQGame游戏同时在线的玩家数量极其庞大,为了方便组织玩家组队游戏,腾讯设置了大量游戏室( ...