Problem 9-Project Euter

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

posted @ 2012-03-29 10:18  AndyDHG  阅读(165)  评论(0编辑  收藏  举报