首页 > 其他 > 详细

ProjectEuler 009题

时间:2014-05-31 01:22:27      阅读:380      评论:0      收藏:0      [点我收藏+]

题目:

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

ProjectEuler 009题

原文:http://www.cnblogs.com/wanghui390/p/3761822.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!