本文主要是介绍FZU 1669 Right-angled Triangle 解毕达哥拉斯三元组,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Accept: 52 Submit: 109
Time Limit: 1000 mSec Memory Limit : 32768 KB
Problem Description
- A right triangle (or right-angled triangle, formerly called a rectangled triangle) has one 90° internal angle (a right angle). The side opposite to the right angle is the hypotenuse; it is the longest side in the right triangle. The other two sides are the legs or catheti (singular: cathetus) of the triangle. Right triangles conform to the Pythagorean Theorem, wherein the sum of the squares of the two legs is equal to the square of the hypotenuse, i.e., a^2 + b^2 = c^2, where a and b are the legs and c is the hypotenuse.
- An oblique triangle has no internal angle equal to 90°.
- An obtuse triangle is an oblique triangle with one internal angle larger than 90° (an obtuse angle).
- An acute triangle is an oblique triangle with internal angles all smaller than 90° (three acute angles). An equilateral triangle is an acute triangle, but not all acute triangles are equilateral triangles.
Input
Output
Sample Input
Sample Output
Hint
There are five right-angled triangles where a + b + c ≤ 40. That are one right-angled triangle where a = 3, b = 4 and c = 5; one right-angled triangle where a = 6, b = 8 and c = 10; one right-angled triangle where a = 5, b = 12 and c = 13; one right-angled triangle where a = 9, b = 12 and c = 15; one right-angled triangle where a = 8, b = 15 and c = 17.
//187 ms 208KB
#include<stdio.h>
#include<math.h>
int gcd(int a,int b)
{return b==0?a:gcd(b,a%b);
}
void solve(int t)
{int tmp=sqrt(t),x,y,z,ans=0;for(int n=1; n<=tmp; n++)for(int m=n+1; m<=tmp; m++){if(2*m*m+2*m*n>t)break;//x+y+z>t结束if(n%2!=m%2){if(gcd(m,n)==1){x=m*m-n*n;y=2*m*n;z=m*m+n*n;for(int i=1;; i++){if(i*(x+y+z)>t)break;ans++;}}}}printf("%d\n",ans);
}
int main()
{int t;while(scanf("%d",&t)!=EOF)solve(t);return 0;
}
这篇关于FZU 1669 Right-angled Triangle 解毕达哥拉斯三元组的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!