Problem 47
The first two consecutive numbers to have two distinct prime factors are:
15 = 3 × 5
The first three consecutive numbers to have three distinct prime factors are:
645 = 3 × 5 × 43
646 = 2 × 17 × 19
Find the first four consecutive integers to have four distinct prime factors. What is the first of these numbers?
首次出现连续两个数均有两个不同的质因数是在:
15 = 3 × 5
首次出现连续三个数均有三个不同的质因数是在:
645 = 3 × 5 × 43
646 = 2 × 17 × 19
首次出现连续四个数均有四个不同的质因数时,其中的第一个数是多少?
def isprime(x):
if x <= 1:
return False
for i in range(2,int(x**0.5+1)):
if x % i == 0:
return False
return True
def find_prime(a,b):
i = a
while i <= b:
if isprime(i):
yield i
i += 1
def factorize(num,factor):
ll = find_prime(2,int(num**0.5+1))
for i in ll:
if num % i == 0:
factor.add(i)
return factorize(int(num/i),factor)
factor.add(num)
return factor
string = ''
for i in range(1,200000):
string += str(len(factorize(i,set())))
print(string.find('4444') + 1)