A Pythagorean triplet is a set of three natural numbers, a
b
c, for which,
a2 + b2 = c2
For example, 32 + 42 = 9 + 16 = 25 = 52.
There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc.
//通项公式
//a=M^2-N^2
//b=2MN
//c=M^2+N^2
//(M,N为正整数)
int main()
{
int a,b,c;
int flag=0;
for(int M=3;M<=33;M++)
{
for(int N=3;N<M;N++)
{
a=M*M-N*N;
b=2*M*N;
c=M*M+N*N;
if(a+b+c==1000) {flag=1;break;}
}
if(flag==1) break;
}
printf("%d,%d,%d",a,b,c);
printf("%d",a*b*c);
return 0;
}
|
Answer:
|
31875000 |
寻找特定勾股数乘积
本文介绍了一种使用C语言编程的方法来找到满足特定条件的勾股数三元组,并计算它们的乘积。通过设定M和N的范围,程序能够有效地找到使得a+b+c等于1000的唯一勾股数三元组。
358

被折叠的 条评论
为什么被折叠?



