ProjectEuler 009题

时间:2014-05-31 01:23:03   收藏:0   阅读:254

题目:

A Pythagorean triplet is a set of three natural numbers, a bubuko.com,布布扣 b bubuko.com,布布扣 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.

代码:

bubuko.com,布布扣
 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 }
bubuko.com,布布扣

 

ProjectEuler 009题,布布扣,bubuko.com

评论(0)
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!