complete 11057.kt 15835.kt 20411.kt 25345.kt 28242.kt 32628.kt

This commit is contained in:
2025-07-29 06:36:46 +09:00
parent 2e957b221e
commit b4b22e9af7
6 changed files with 268 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
fun main() = with(System.`in`.bufferedReader()) {
val iter = this.readLine().split(" ").iterator()
val m = iter.next().toLong()
val seed = iter.next().toLong()
val x1 = iter.next().toLong()
val x2 = iter.next().toLong()
// x1 = (a * seed + c) % m
// x2 = (a * x1 + c) % m
(0 until m).asSequence().map { a ->
val t = (a * seed) % m
val c = if (t <= x1) {
x1 - t
} else {
m - (t - x1)
}
a to c
}.first { (a, c) ->
x2 == (a * x1 + c) % m
}.let { (a, c) ->
println("$a $c")
}
}