You are viewing a single comment's thread. Return to all comments →
Not sure, but this works:
N = 10**6 moves = [0] + N * [N] for i in range(N): moves[i+1] = min(moves[i+1], moves[i] + 1) j = 2 while j <= i and j * i <= N: moves[i * j] = min(moves[i * j], moves[i] + 1) j += 1 for _ in range(int(input())): print(moves[int(input())])
Seems like cookies are disabled on this browser, please enable them to open this website
Down to Zero II
You are viewing a single comment's thread. Return to all comments →
Not sure, but this works: