ProjectEuler 009题
时间:2014-05-31 01:23:03
收藏:0
阅读:254
题目:
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.
代码:
1 #include<iostream> 2 using namespace std; 3 4 int main() { 5 6 for(int i = 1; i < 333; i++){ 7 for(int j = 1; j <= 999; j++) 8 for(int k = 1; k <= 999; k++){ 9 if((i*i + j*j) == (k*k) && (i+j+k) == 1000) 10 cout << i << " " << j << " " << k << endl; 11 } 12 } 13 14 system("pause"); 15 return 0; 16 }
评论(0)
