Project Euler #52: Permuted multiples

  • + 0 comments

    100% python3

    # Enter your code here. Read input from STDIN. Print output to STDOUT
    
    N, k = map(int, input().split())
    
    primes = {0: 2, 1: 3, 2: 5, 3: 7, 4: 11, 5: 13, 6: 17, 7: 19, 8: 23, 9:29}
    
    def rootval(n):
        s = 1
        while n > 0:
            s *= primes[n%10]
            n = n // 10
        return(s)
        
    n = 125874
    while n <= N:
        tmp, val = [n], rootval(n)
        for i in range(2, k+1):
            if val == rootval(n*i):
                tmp.append(n*i)
            else:
                break
        else:
            print(*tmp)
        n += 1