The first two consecutive numbers to have two distinct prime factors are:
14 = 2 × 7
15 = 3 × 5
The first three consecutive numbers to have three distinct prime factors are:
644 = 2² × 7 × 23
645 = 3 × 5 × 43
646 = 2 × 17 × 19.
Find the first four consecutive integers to have four distinct prime factors each. What is the first of these numbers?
In [1]:
def prime_factors(n):
factors = []
d = 2
while n > 1:
while n % d == 0:
factors.append(d)
n /= d
d = d + 1
if d * d > n:
if n > 1:
factors.append(n)
break
return factors
In [2]:
def has_stretch(s_len):
found_stretch = True
for c in range(s_len):
pf = set(prime_factors(n+c))
if len(pf) != s_len:
found_stretch = False
break
return found_stretch
for n in range(10**6):
if has_stretch(s_len=4):
print n
break