project-euler/131_prime_cube_partnership.py

26 lines
400 B
Python

#!/usr/bin/env python3
def primes(n):
sieve = [False] * n
for p in range(2, n):
if sieve[p]:
continue
for i in range(p**2, n, p):
sieve[i] = True
return sieve
bound = 10**6
sieve = primes(bound)
c = 0
n = 1
cube_diff = 7
while cube_diff < bound:
if not sieve[cube_diff]:
c += 1
n += 1
cube_diff = 3*n**2 + 3*n + 1
print(c)