combinatoric selections problem 47 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 find unique prime factors of an integer tests include sorting because only the set really matters not the order in which it is produced sortedsetuniqueprimefactors14 2 7 sortedsetuniqueprimefactors644 2 7 23 sortedsetuniqueprimefactors646 2 17 19 memoize upf length results for a given value upflen14 2 check equality of all elements in an interable equality1 2 3 4 false equality2 2 2 2 true equality1 2 3 2 1 false runs core process to find problem solution run3 644 645 646 incrementor variable for our group list comprehension this serves as the first number in each list of values to test increment each value of a generated range run elements through out uniqueprimefactors function append our target number to the end if all numbers in the list are equal return the group variable increment our base variable by 1 return the first value of the first four consecutive integers to have four distinct prime factors each solution 134043 find unique prime factors of an integer tests include sorting because only the set really matters not the order in which it is produced sorted set unique_prime_factors 14 2 7 sorted set unique_prime_factors 644 2 7 23 sorted set unique_prime_factors 646 2 17 19 memoize upf length results for a given value upf_len 14 2 check equality of all elements in an interable equality 1 2 3 4 false equality 2 2 2 2 true equality 1 2 3 2 1 false runs core process to find problem solution run 3 644 645 646 incrementor variable for our group list comprehension this serves as the first number in each list of values to test increment each value of a generated range run elements through out unique_prime_factors function append our target number to the end if all numbers in the list are equal return the group variable increment our base variable by 1 return the first value of the first four consecutive integers to have four distinct prime factors each solution 134043
from functools import lru_cache


def unique_prime_factors(n: int) -> set:
    
    i = 2
    factors = set()
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.add(i)
    if n > 1:
        factors.add(n)
    return factors


@lru_cache
def upf_len(num: int) -> int:
    
    return len(unique_prime_factors(num))


def equality(iterable: list) -> bool:
    
    return len(set(iterable)) in (0, 1)


def run(n: int) -> list:
    

    
    
    
    base = 2

    while True:
        
        group = [base + i for i in range(n)]

        
        
        checker = [upf_len(x) for x in group]
        checker.append(n)

        
        if equality(checker):
            return group

        
        base += 1


def solution(n: int = 4) -> int:
    
    results = run(n)
    return results[0] if len(results) else None


if __name__ == "__main__":
    print(solution())