[Baekjoon] 2331 반복수열 python

sorzzzzy·2021년 8월 4일
0

Baekjoon Algorithm

목록 보기
17/46
post-thumbnail

🏷 문제


💡 코드

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)

🔑

profile
Backend Developer

0개의 댓글