-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path139.py
More file actions
23 lines (22 loc) · 689 Bytes
/
139.py
File metadata and controls
23 lines (22 loc) · 689 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from math import *
def triple(n, m):
# use euler's equation to generate
assert m > n > 0
return tuple(sorted((2*n*m, m**2-n**2, n**2+m**2)))
target = 100_000_000
from collections import defaultdict
triangles = defaultdict(set)
res = set()
for m in range(1, floor(sqrt(target))+1):
for n in range(1, m):
triangle = triple(n, m)
if sum(triangle) > target:
break
curr = 1
original = triangle
while sum(triangle) < target:
triangle = tuple(t*curr for t in original)
if max(triangle) % abs(triangle[0]-triangle[1]) == 0:
res.add(triangle)
curr += 1
print(len(res))