[Baekjoon] 2331 반복수열 python

🏷 문제


💡 코드

a, p = map(int, input().split())

seq = []
seq.append(a)
num = a
while True:
    res = 0
    for i in str(num):
        res += int(i)**p
    if res in seq:
        idx = seq.index(res)
        break
    else:
        seq.append(res)
        num = res
        # print(seq)
print(idx)

🔑

좋은 웹페이지 즐겨찾기