https://www.acmicpc.net/problem/2331
import java.util.*;
import kotlin.math.*;
fun make(a:Int,p:Int):Int{
var sum=0
var m=a
while(m>0){
var k=m%10
sum+=(k.toDouble()).pow(p).toInt()
m/=10
}
return sum;
}
fun main(args: Array<String>) {
var arr=ArrayList<Int>()
val s=Scanner(System.`in`)
var a=s.nextInt()
var p=s.nextInt()
arr.add(a)
while(true){
var m=arr.get(arr.size-1)
var num=make(m,p)
if(arr.contains(num)){
var ans=arr.indexOf(num)
print(ans)
break
}
arr.add(num)
}
}