Project Euler Problem 9-Special Pythagorean triplet

我是俩循环暴力
看了看给的文档,英语并不好,有点懵,所以找了个中文的博客看了看: 勾股数组学习小记。里面有两个学习链接和例题。

import math


def calc():
    for i in range(1,1000):
        j = i+1
        while j <= 1000:
            c = i*i+j*j
            c = int(math.sqrt(c))
            if i+j+c > 1000:
                break
            if i < j < c and i+j+c == 1000 and i*i+j*j == c*c:
                return i,j,c
            j += 1
    return 0,0,0


a,b,c = calc()
print a,b,c
print a*b*c
posted @ 2017-09-21 23:28  追梦的蚂蚁  阅读(138)  评论(0编辑  收藏  举报