結果

問題 No.673 カブトムシ
ユーザー rutilicusrutilicus
提出日時 2020-12-27 14:27:47
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 325 ms / 2,000 ms
コード長 966 bytes
コンパイル時間 13,505 ms
コンパイル使用メモリ 437,652 KB
実行使用メモリ 54,504 KB
最終ジャッジ日時 2024-04-08 21:58:47
合計ジャッジ時間 20,239 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 315 ms
54,500 KB
testcase_01 AC 317 ms
54,492 KB
testcase_02 AC 318 ms
54,480 KB
testcase_03 AC 319 ms
54,484 KB
testcase_04 AC 317 ms
54,480 KB
testcase_05 AC 317 ms
54,496 KB
testcase_06 AC 316 ms
54,484 KB
testcase_07 AC 316 ms
54,496 KB
testcase_08 AC 315 ms
54,496 KB
testcase_09 AC 318 ms
54,484 KB
testcase_10 AC 315 ms
54,480 KB
testcase_11 AC 317 ms
54,500 KB
testcase_12 AC 320 ms
54,496 KB
testcase_13 AC 320 ms
54,496 KB
testcase_14 AC 318 ms
54,484 KB
testcase_15 AC 317 ms
54,504 KB
testcase_16 AC 319 ms
54,496 KB
testcase_17 AC 325 ms
54,496 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:11:17: warning: 'appendln(Long): kotlin.text.StringBuilder /* = java.lang.StringBuilder */' is deprecated. Use appendLine instead. Note that the new method always appends the line feed character '\n' regardless of the system line separator.
        builder.appendln((b % mod) * (d % mod) % mod)
                ^
Main.kt:16:17: warning: 'appendln(Long): kotlin.text.StringBuilder /* = java.lang.StringBuilder */' is deprecated. Use appendLine instead. Note that the new method always appends the line feed character '\n' regardless of the system line separator.
        builder.appendln(ans)
                ^

ソースコード

diff #

fun main() {
    val builder = StringBuilder()

    // modきらい
    // ほかの解答コード写経したけど何をしているのか全然わからない……
    val mod = 1000000007L

    val (b, c, d) = readInputLine().split(" ").map { it.toLong() }

    if (c % mod == 1L) {
        builder.appendln((b % mod) * (d % mod) % mod)
    } else {
        val t1 = (b % mod) * (c % mod) % mod
        val t2 = (mod - t1) % mod * pow((c - 1L) % mod, mod - 2L, mod) % mod
        val ans = ((t1 - t2 + mod) % mod * pow(c % mod, d - 1L, mod) % mod + t2) % mod
        builder.appendln(ans)
    }

    print(builder.toString())
}

fun readInputLine(): String {
    return readLine()!!
}

fun pow(x: Long, n: Long, mod: Long): Long {
    var ret = 1L
    var base = x
    var nTmp = n

    while (nTmp != 0L) {
        if (nTmp % 2L != 0L) {
            ret = ret * base % mod
        }
        base = base * base % mod
        nTmp /= 2L
    }

    return ret
}
0