結果

問題 No.2176 LRM Question 1
ユーザー 👑 箱星箱星
提出日時 2022-09-19 22:07:13
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 1,201 bytes
コンパイル時間 17,409 ms
コンパイル使用メモリ 441,412 KB
実行使用メモリ 50,184 KB
最終ジャッジ日時 2024-04-16 11:33:15
合計ジャッジ時間 23,849 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 296 ms
49,920 KB
testcase_02 AC 291 ms
49,776 KB
testcase_03 AC 298 ms
49,836 KB
testcase_04 AC 291 ms
50,020 KB
testcase_05 AC 292 ms
50,004 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 292 ms
49,768 KB
testcase_12 AC 287 ms
49,804 KB
testcase_13 AC 294 ms
50,076 KB
testcase_14 AC 339 ms
49,952 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 291 ms
49,860 KB
testcase_18 AC 290 ms
50,052 KB
testcase_19 AC 301 ms
49,808 KB
testcase_20 AC 295 ms
49,932 KB
testcase_21 AC 295 ms
50,080 KB
testcase_22 WA -
testcase_23 AC 295 ms
49,932 KB
testcase_24 AC 293 ms
49,816 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
    for (i in 1..l) {
        fac *= i
        fac %= m
    }
    var ans = 0L
    var prod = fac
    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