http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=11351&courseid=0

Problem description

The famous Pythagorean theorem states that a right triangle, having side lengthsA and B and hypotenuse length C, satisfies the formula

A 2 + B 2 = C 2

It is also well known that there exist some right triangles in which all three side lengths are integral, such as the classic:

Further examples, both having A=12, are the following:

The question of the day is, given a fixed integer value for A, how many distinct integersB > A exist such that the hypotenuse length C is integral?

Input

Each line contains a single integer A, such that

2 ≤ A < 1048576 = 2
20
. The end of the input is designated by a line containing the value 0.

Output

For each value of A, output the number of integers B > A such that a right triangle having side lengthsA and B has a hypotenuse with integral length.

Sample Input
3
12
2
1048574
1048575
0
Sample Output
1
2
0
1
175
Judge Tips

A Hint and a Warning: Our hint is that you need not consider any value forB that is greater than ( A 2-1)/2 , because for any such right triangle, hypotenuse C satisfies B < C < B + 1 , and thus cannot have integral length.

Our warning is that for values of A ≈ 2 20 , there could be solutions with B ≈ 2 39 , and thus values of C 2 > B 2 ≈ 2 78.

You can guarantee yourself 64-bit integer calculations by using the type long long in C++ or long in Java. But neither of those types will allow you to accurately calculate the value ofC2 for such an extreme case. (Which is, after all, what makes thisPythagoras's revenge!)

题意:给出一条最短的直角边,要求另外两边都是整数的直角三角形的个数

思路:根据勾股定理a^2+b^2=c^2

可得:a^2=(c-b)(c+b)

令x = c-b;

y=c+b;

又y-x=2*b;

所以b=(y-x)/2;

并且需要b>a,所以只需要对x进行枚举即可

#include <iostream>
#include <cmath>
using namespace std; int main()
{
while (true)
{
long long a;
cin >> a;
if (a == 0) break; long long count;
count = 0;
for (long long x=1; x <= a/2; x++)
{
if (a*a % x == 0)
{
long long y = a*a / x;
if ((y-x)%2 == 0)
{
long long b = (y-x)/2;
if (b > a)
{
count++;
}
}
}
}
cout << count << endl;
}
}

HUNNU11351:Pythagoras's Revenge的更多相关文章

  1. hdu_4787_GRE Words Revenge(在线AC自动机)

    题目链接:hdu_4787_GRE Words Revenge 题意: 总共有n个操作,2种操作.每行读入一个字符串. 1.如果字符串以+开头,此为单词(即模式串,不考虑重复) 2.如果字符串以?开头 ...

  2. hdu_3341_Lost's revenge(AC自动机+状态hashDP)

    题目链接:hdu_3341_Lost's revenge 题意: 有n个模式串,一个标准串,现在让标准串重组,使得包含最多的模式串,可重叠,问重组后最多包含多少模式串 题解: 显然是AC自动机上的状态 ...

  3. hdoj 5087 Revenge of LIS II 【第二长单调递增子】

    称号:hdoj 5087 Revenge of LIS II 题意:非常easy,给你一个序列,让你求第二长单调递增子序列. 分析:事实上非常easy.不知道比赛的时候为什么那么多了判掉了. 我们用O ...

  4. 四校训练 warm up 14

    A:Pythagoras's Revenge 代码: #include<cstdio> #define ll long long using namespace std; int main ...

  5. 2017 ACM/ICPC Asia Regional Qingdao Online Solution

    A : Apple 题意:给出三个点,以及另一个点,求最后一个点是否在三个点的外接圆里面,如果在或者在边界上,输出“Rejected”,否则输出"Accepted" 思路:先求一个 ...

  6. java web 开发三剑客 -------电子书

    Internet,人们通常称为因特网,是当今世界上覆盖面最大和应用最广泛的网络.根据英语构词法,Internet是Inter + net,Inter-作为前缀在英语中表示“在一起,交互”,由此可知In ...

  7. 所有selenium相关的库

    通过爬虫 获取 官方文档库 如果想获取 相应的库 修改对应配置即可 代码如下 from urllib.parse import urljoin import requests from lxml im ...

  8. 数论(毕达哥拉斯定理):POJ 1305 Fermat vs. Pythagoras

    Fermat vs. Pythagoras Time Limit: 2000MS   Memory Limit: 10000K Total Submissions: 1493   Accepted: ...

  9. 刷题记录:[LCTF]bestphp's revenge

    目录 刷题记录:[LCTF]bestphp's revenge 一.知识点 1.SoapClient触发反序列化导致ssrf 2.serialize_hander处理session方式不同导致sess ...

随机推荐

  1. Fedora 问题总结第二季

    该系列主要是记录自己使用fedora发现的问题. 1Linux Error: curses.h: No such file or directory Problem Solution sudo yum ...

  2. viewDidLoad、viewDidUnload、viewWillAppear、viewDidAppear、viewWillDisappear 和 -viewDidDisappear的区别和使用

    首先看一下官方解释: - (void)loadView; // This is where subclasses should create their custom view hierarchy i ...

  3. mysql基础: mysql列类型--字符串

    mysql列类型:整型   http://blog.csdn.net/jk110333/article/details/9342283 mysql列类型--时间和日期  http://blog.csd ...

  4. 《Struts2技术内幕》学习笔记

    第2.3章 基础 三种类模式:属性-行为模式.属性模式.行为模式. 其中属性模式有:PO(持久化对象).BO(业务对象).VO(值对象).DTO(传输数据对象).FromBean(页面对象)他们是对J ...

  5. How to get the source code of the chromium of the specified revision

    I'd like to get the source code of the chromium 34.0.1847.9. gclient config http://src.chromium.org/ ...

  6. php获取server端mac和clientmac的地址

    获取servermac <?php /** 获取网卡的MAC地址原码:眼下支持WIN/LINUX系统 获取机器网卡的物理(MAC)地址 **/ class GetmacAddr{ var $re ...

  7. 面向接口可扩展框架之“Mvc扩展框架及DI”

    面向接口可扩展框架之“Mvc扩展框架及DI” 标题“Mvc扩展框架及DI”有点绕口,我也想不出好的命名,因为这个内容很杂,涉及多个模块,但在日常开发又密不可分 首先说Mvc扩展框架,该Mvc扩展就是把 ...

  8. Android中九种dialog对话框代码

    public class MainActivity extends Activity { private static final int MAX_PROGRESS = 100; private st ...

  9. 理解 Python 中的线程

    原地址:http://blog.jobbole.com/52060/ 本文由 伯乐在线 - acmerfight 翻译自 Akshar Raaj.欢迎加入技术翻译小组.转载请参见文章末尾处的要求. 我 ...

  10. OCP读书笔记(5) - 使用RMAN创建备份

    5.Creating Backups with RMAN 创建备份集 RMAN> backup as backupset format '/u01/app/oracle/backup/rmanb ...