1157(A,kt): solve “Reachable Numbers”

Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
Matej Focko 2023-07-09 22:54:49 +02:00
parent 54ade11dd9
commit 3ad2018645
Signed by: mfocko
GPG key ID: 7C47D46246790496
2 changed files with 1392 additions and 0 deletions

23
1157/A.kt Normal file
View file

@ -0,0 +1,23 @@
//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))
}

1369
1157/index.html Normal file

File diff suppressed because it is too large Load diff