[백준] 2331번 : 반복수열 - Python(파이썬)

강재원·2022년 11월 24일
0

[코딩테스트] Python

목록 보기
186/200



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

import math

def make(a,p):
    sum=0
    while a>0:
        sum+=int(math.pow(a%10,p))
        a//=10
    return sum

arr=[]
a,p=map(int,input().split())
arr.append(a)
while 1:
    m=arr[len(arr)-1]
    num=make(m,p)

    if arr.__contains__(num):
        ans=arr.index(num)
        print(ans)
        break
    arr.append(num)
profile
개념정리 & 문법 정리 & 알고리즘 공부

0개의 댓글