HUNNU11351:Pythagoras's Revenge
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
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 |
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 |
Sample Output |
1 |
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> |
HUNNU11351:Pythagoras's Revenge的更多相关文章
- hdu_4787_GRE Words Revenge(在线AC自动机)
题目链接:hdu_4787_GRE Words Revenge 题意: 总共有n个操作,2种操作.每行读入一个字符串. 1.如果字符串以+开头,此为单词(即模式串,不考虑重复) 2.如果字符串以?开头 ...
- hdu_3341_Lost's revenge(AC自动机+状态hashDP)
题目链接:hdu_3341_Lost's revenge 题意: 有n个模式串,一个标准串,现在让标准串重组,使得包含最多的模式串,可重叠,问重组后最多包含多少模式串 题解: 显然是AC自动机上的状态 ...
- hdoj 5087 Revenge of LIS II 【第二长单调递增子】
称号:hdoj 5087 Revenge of LIS II 题意:非常easy,给你一个序列,让你求第二长单调递增子序列. 分析:事实上非常easy.不知道比赛的时候为什么那么多了判掉了. 我们用O ...
- 四校训练 warm up 14
A:Pythagoras's Revenge 代码: #include<cstdio> #define ll long long using namespace std; int main ...
- 2017 ACM/ICPC Asia Regional Qingdao Online Solution
A : Apple 题意:给出三个点,以及另一个点,求最后一个点是否在三个点的外接圆里面,如果在或者在边界上,输出“Rejected”,否则输出"Accepted" 思路:先求一个 ...
- java web 开发三剑客 -------电子书
Internet,人们通常称为因特网,是当今世界上覆盖面最大和应用最广泛的网络.根据英语构词法,Internet是Inter + net,Inter-作为前缀在英语中表示“在一起,交互”,由此可知In ...
- 所有selenium相关的库
通过爬虫 获取 官方文档库 如果想获取 相应的库 修改对应配置即可 代码如下 from urllib.parse import urljoin import requests from lxml im ...
- 数论(毕达哥拉斯定理):POJ 1305 Fermat vs. Pythagoras
Fermat vs. Pythagoras Time Limit: 2000MS Memory Limit: 10000K Total Submissions: 1493 Accepted: ...
- 刷题记录:[LCTF]bestphp's revenge
目录 刷题记录:[LCTF]bestphp's revenge 一.知识点 1.SoapClient触发反序列化导致ssrf 2.serialize_hander处理session方式不同导致sess ...
随机推荐
- .htaccess和license文件编写
1 .htaccess 1.1 文件的位置 默认情况下放置于根目录 1.2 .htaccess文件的编写 1.2.1 错误页面跳转 ErrorDocument + 错误码 + 跳转路径/提示文字 eg ...
- OSGi:生命周期层
前言 生命周期层在OSGi框架中属于模块层上面的一层,它的运作是建立在模块层的功能之上的.生命周期层一个主要的功能就是让你能够从外部管理应用或者建立能够自我管理的应用(或者两者的结合),并且给了应用本 ...
- 转载【浅谈ThreadPool 线程池】
浅谈ThreadPool 线程池 http://www.cnblogs.com/xugang/archive/2010/04/20/1716042.html
- 让XP系统支持GPT硬盘
转自 http://article.pchome.net/content-1324506-all.html 1XP系统还不过时 教你完美征服3TB硬盘回顶部 原作者:沈洁 随着高清1080p片源的普及 ...
- [Android学习笔记]Fragment使用
一.android.app.Fragment 与 android.support.v4.app.Fragment 区别 support.v4.app.Fragment是为了给低版本Android使用的 ...
- POJ 2442 Squence (STL heap)
题意: 给你n*m的矩阵,然后每行取一个元素,组成一个包含n个元素的序列,一共有n^m种序列, 让你求出序列和最小的前n个序列的序列和. 解题思路: 1.将第一序列读入seq1向量中,并按升序排序. ...
- 链栈之C++实现
链栈是借用单链表实现的栈.其不同于顺序栈之处在于: 1.链栈的空间是程序运行期间根据需要动态分配的,机器内存是它的上限.而顺序栈则是 静态分配内存的. 2.链栈动态分配内存的特性使得它一般无需考虑栈溢 ...
- 使用PageHeap.EXE或GFlags.EXE检查内存越界错误
必先利其器之一:使用PageHeap.EXE或GFlags.EXE检查内存越界错误 Article last modified on 2002-6-3 ------------------------ ...
- ubuntu14.04中virtualbox虚拟机无法启动
近期升级了ubuntu14.04,还是按之前的方法安装了virtualbox(guest系统仍然使用升级之前的镜像文件),可是在启动guest系统时,总是报错,提演示样例如以下: Kernel dri ...
- Android UI布局TableLayout
了解字面上TableLayout一个表格样式布局.这种布局将包括以行和列的形式的元件被布置.表格列的数目是列的各行中的最大数目.当然,表格里面的单元格它能够清空. 实例:LayoutDemo 执行效果 ...