結果

問題 No.2176 LRM Question 1
ユーザー 👑 箱
提出日時 2022-09-19 22:14:25
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 343 ms / 2,000 ms
コード長 1,238 bytes
コンパイル時間 15,528 ms
コンパイル使用メモリ 440,040 KB
実行使用メモリ 50,132 KB
最終ジャッジ日時 2024-04-16 11:33:41
合計ジャッジ時間 24,200 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 296 ms
49,940 KB
testcase_01 AC 294 ms
50,076 KB
testcase_02 AC 299 ms
50,040 KB
testcase_03 AC 294 ms
50,052 KB
testcase_04 AC 294 ms
49,732 KB
testcase_05 AC 315 ms
49,736 KB
testcase_06 AC 299 ms
49,988 KB
testcase_07 AC 296 ms
49,792 KB
testcase_08 AC 294 ms
49,924 KB
testcase_09 AC 296 ms
49,844 KB
testcase_10 AC 297 ms
49,816 KB
testcase_11 AC 292 ms
49,776 KB
testcase_12 AC 293 ms
49,900 KB
testcase_13 AC 297 ms
49,948 KB
testcase_14 AC 343 ms
49,856 KB
testcase_15 AC 305 ms
50,068 KB
testcase_16 AC 305 ms
50,080 KB
testcase_17 AC 296 ms
49,824 KB
testcase_18 AC 292 ms
49,988 KB
testcase_19 AC 297 ms
49,820 KB
testcase_20 AC 293 ms
49,984 KB
testcase_21 AC 293 ms
49,824 KB
testcase_22 AC 296 ms
49,916 KB
testcase_23 AC 296 ms
50,132 KB
testcase_24 AC 291 ms
49,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter
import java.util.*
import kotlin.math.*

fun PrintWriter.solve() {
    val l = nextLong()
    val r = nextLong()
    val m = nextInt()
    if (l >= m) {
        println(0)
        return
    }
    var fac = 1L
    var prod = 1L
    for (i in 1..l) {
        fac *= i
        fac %= m
        prod *= fac
        prod %= m
    }
    var ans = 0L
    for (n in l..r) {
        ans += prod
        ans %= m
        fac *= (n + 1)
        fac %= m
        prod *= fac
        prod %= m
        if (prod == 0L) break
    }
    println(ans)
}

fun main() {
    Thread(null, {
        val writer = PrintWriter(System.out, false)
        writer.solve()
        writer.flush()
    }, "solve", abs(1L.shl(26)))
        .apply { setUncaughtExceptionHandler { _, e -> e.printStackTrace(); kotlin.system.exitProcess(1) } }
        .apply { start() }.join()
}

// region Scanner
private var st = StringTokenizer("")
private val br = System.`in`.bufferedReader()

fun next(): String {
    while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())
    return st.nextToken()
}

fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextLine() = br.readLine()
fun nextDouble() = next().toDouble()
// endregion
0