不用别人认可也不用别人理解,尽情去做自己认为应该做的事……

2009年5月6日星期三

Problem 9--(c)

Problem 9
25 January 2002

A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
a^(2) + b^(2) = c^(2)

For example, 3^(2) + 4^(2) = 9 + 16 = 25 = 5^(2).

There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.

Answer:
31875000
#include
int main(void)
{
int i,j;
for(i=1;i<=500;i++)
for(j=1;j<500;j++)
{
if(i*i+j*j==(1000-i-j)*(1000-i-j))
printf("%d\n",i*j*(1000-i-j));
}
return 0;
}

0 评论: