project-euler/135_same_differences.py

20 lines
336 B
Python

#!/usr/bin/env python3
N = 10 ** 6
target = 10
sieve = [0] * N
m = 3
while 2*m - 1 < 3*N:
n = m - 1 - (not m % 2)
i = (m - n) * (m + n)
while i < 3*N and n > 0:
if not i % 3 and not (m - (n//2)) % 3:
sieve[i//3] += 1
n -= 2
i = (m - n) * (m + n)
m += 1
print(sieve.count(target))