|
发表于 2017-1-14 15:16:20
|
显示全部楼层
- # encoding:utf-8
- # 寻找周长1000以下,能够成直角三角形最多的数
- from time import time
- def euler039():
- maxcount = 0
- result = []
- for p in range(12, 1001):
- count = 0
- tmp = []
- for i in range(int(p / (1 + 2 ** 0.5)) - 1, int(p / 2) + 1):
- for j in range(int(i / (2 ** 0.5)) - 1, i):
- if i ** 2 == j ** 2 + (p - i - j) ** 2:
- count += 1
- tmp.append((p, i, j, (p - i - j)))
- break
- if count > maxcount:
- result = tmp
- maxcount = count
- print(maxcount, result)
- if __name__ == '__main__':
- start = time()
- euler039()
- print('cost %.6f sec' % (time() - start))
复制代码
8 [(840, 348, 252, 240), (840, 350, 280, 210), (840, 357, 315, 168), (840, 364, 336, 140), (840, 370, 350, 120), (840, 375, 360, 105), (840, 394, 390, 56), (840, 401, 399, 40)]
cost 5.641026 sec |
|