project-euler/136_singleton_differences.py

20 lines
340 B
Python

#!/usr/bin/env python3
N = 50 * 10 ** 6
target = 1
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))