Codeforces/1157/A.kt
Matej Focko 3ad2018645
1157(A,kt): solve “Reachable Numbers”
Signed-off-by: Matej Focko <me@mfocko.xyz>
2023-07-10 09:56:54 +02:00

23 lines
417 B
Kotlin

//import readInt
fun removeTrailingZeros(n: Int): Int =
if (n % 10 == 0)
removeTrailingZeros(n / 10)
else
n
fun f(n: Int): Int = removeTrailingZeros(n + 1)
fun findReachable(n: Int): Int {
val reachable = mutableSetOf<Int>()
var m = n
while (reachable.add(m)) m = f(m)
return reachable.size
}
fun main() {
val n = readLine()!!.toInt()
println(findReachable(n))
}