Problem 52 Permuted multiples

2016-11-17 13:20:00   技术   python projecteulor

It can be seen that the number, 125874, and its double, 251748, contain exactly the same digits, but in a different order.

Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x, contain the same digits. result = 1

while True:
    result_str = list(str(result))
    result_str.sort()
    flag = True
    for p in reversed(range(2, 7)):
        target = p * result
        target_str = list(str(target))
        target_str.sort()
        if not target_str == result_str:
            flag = False
            break
    if flag:
        print result
        break
    result += 1

感觉很简单的样子

评论已关闭。
评论共