project-euler/204_generalised_hamming_num...

23 lines
490 B
Python
Raw Normal View History

#!/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 [p for p, t in enumerate(sieve) if not t][2:]
def rec(n, nums, i, lim):
c = 1
for j, f in enumerate(nums[i:], start=i):
new = f*n
if new > lim:
break
c += rec(new, nums, j, lim)
return c
nums = primes(100)
print(rec(1, nums, 0, 10**9))