码迷,mamicode.com
首页 > 其他好文 > 详细

ProjectEuler 009题

时间:2014-05-31 01:23:03      阅读:254      评论:0      收藏:0      [点我收藏+]

标签:c   style   class   blog   code   java   

题目:

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题

标签:c   style   class   blog   code   java   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!