码迷,mamicode.com
首页 > 编程语言 > 详细

欧拉计划(python) problem 9

时间:2015-01-27 09:32:08      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:

Special Pythagorean triplet

Problem 9

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.


python code:


for i in range(1,1000):
    id=0
    for j in range(i,1000):
        c=1000-i-j
        if c<=0:
            continue
        else:
            if i*i+j*j!=c*c:
                continue
            else:
                print(i*j*c)
                id=1
                break
    if id==1:
        break


result : 31875000

time : <1s


欧拉计划(python) problem 9

标签:

原文地址:http://blog.csdn.net/zhangzhengyi03539/article/details/43164593

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