HUNNU11351:Pythagoras's Revenge
来源:互联网 发布:java怎么调用数组 编辑:程序博客网 时间:2024/06/07 05:56
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 andB and hypotenuse length C, satisfies the formula
A2 +B2 =C2
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 lengthC is integral?
Each line contains a single integer A, such that
For each value of A, output the number of integers B > A such that a right triangle having side lengthsA andB has a hypotenuse with integral length.
Sample Input3122104857410485750Sample Output
1201175Judge Tips
A Hint and a Warning: Our hint is that you need not consider any value forB that is greater than
Our warning is that for values of
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
- Pythagoras's Revenge
- SDNU 1147 Pythagoras's Revenge 【技巧暴力】
- Lost's revenge hdu3341
- HDU3341--Lost's revenge
- HDU3341 Lost's revenge
- UVa816 Abbott's Revenge
- uva816 Abbott's Revenge
- 816 - Abbott's Revenge
- Abbott‘s Revenge
- [c] sdnuoj1147Pythagoras's Revenge
- UVa816 Abbott's Revenge
- 816 - Abbott's Revenge
- Minimum’s Revenge
- hdu5922Minimum’s Revenge+水题
- uva816 Abbott’s Revenge
- Abbott's Revenge UVA
- Minimum’s Revenge
- CentOS比较好的第三方软件源
- android.os.PowerManager api运用
- Android EditText设置imeOptions没有效果的解决方法
- 根据font的大小 和string来 动态 获取label的长度
- Silverlight中打印文件
- HUNNU11351:Pythagoras's Revenge
- Machine Schedule (二分匹配)
- HDU 4631 Sad Love Story
- android_IntentService,AsyncTask,Handler
- http://www.csdn.net/articlehttp://www.csdn.net/article/2013-08-29/2816749-Non-Programming-game-tools
- MKMapView小结
- 项目估算-非编码任务的工作产品规模估算
- 在手机浏览器上显示web页面
- QT应用程序中debug和release包含不同的库