首页 > 代码库 > Special Pythagorean triplet

Special Pythagorean triplet

problem 9:Special Pythagorean triplet

题意:若a+b+c=1000,且a2+b2=c2,求abc

代码如下:

 1 #ifndef PRO9_H_INCLUDED
 2 #define PRO9_H_INCLUDED
 3 
 4 int solve(){
 5     for(int i=1;i<=1000;++i)
 6     for(int j=1;i+j<1000;++j)
 7         if(i*i+j*j==(1000-i-j)*(1000-i-j))
 8             return i*j*(1000-i-j);
 9 }
10 
11 #endif // PRO9_H_INCLUDED

 

Special Pythagorean triplet