为了锻炼编程的实际能力,从现在开始着手开始计算欧拉项目。

今天是第9题,相对简单的一道题。

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.

寻找一组勾股数,使得三个数的和为1000,求这组数的乘积。程序较为简单,用C语言进行实现:
#include
int main(void)
{
int a,b,c;
for(a=3;a<332;a++) { for(b=a+1;b<997;b++) { c=1000-a-b; if(c<=0&&c
 
结果:a=200,b=375,c=425,乘积为31875000。

作者 hsyyf

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注