Baekjun-グラフ(#2331)


https://www.acmicpc.net/problem/2331

Code

n, p = map(int, input().split())
d = [n]

while True:
    nxt = sum([int(x)**p for x in str(d[-1])])
    if nxt not in d :
        d.append(nxt)
    else:
        i = d.index(nxt)
        d = d[:i]
        break

print(len(d))