結果

問題 No.673 カブトムシ
ユーザー rutilicusrutilicus
提出日時 2020-12-20 11:25:29
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 1,224 bytes
コンパイル時間 17,555 ms
コンパイル使用メモリ 445,560 KB
実行使用メモリ 54,528 KB
最終ジャッジ日時 2023-10-21 10:32:39
合計ジャッジ時間 25,288 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 335 ms
54,516 KB
testcase_03 AC 330 ms
54,524 KB
testcase_04 AC 334 ms
54,524 KB
testcase_05 AC 343 ms
54,524 KB
testcase_06 AC 330 ms
54,512 KB
testcase_07 AC 334 ms
54,528 KB
testcase_08 AC 328 ms
54,508 KB
testcase_09 WA -
testcase_10 AC 326 ms
54,512 KB
testcase_11 AC 330 ms
54,508 KB
testcase_12 AC 323 ms
54,524 KB
testcase_13 AC 323 ms
54,524 KB
testcase_14 AC 335 ms
54,524 KB
testcase_15 AC 327 ms
54,508 KB
testcase_16 AC 332 ms
54,512 KB
testcase_17 AC 340 ms
54,508 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:9: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 * d % mod)
                ^
Main.kt:13: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 * numerator % mod * denominator % mod) + mod - (b % mod)) % mod)
                ^

ソースコード

diff #

fun main() {
    val builder = StringBuilder()

    val mod = 1000000007L

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

    if (c == 1L) {
        builder.appendln(b * d % mod)
    } else {
        val numerator = (pow(c % mod, d + 1L, mod) + mod - 1L) % mod
        val denominator = modInv((c - 1L) % mod, mod) % mod
        builder.appendln(((b % mod * numerator % mod * denominator % mod) + mod - (b % mod)) % mod)
    }

    print(builder.toString())
}

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

// a^-1 mod mod
fun modInv(a: Long, mod: Long): Long {
    var aLoc = a
    var b = mod
    var u = 1L
    var v = 0L
    while (b != 0L) {
        val t = aLoc / b
        aLoc -= t * b

        val swapTmpB = b
        b = aLoc
        aLoc = swapTmpB

        u -= t * v

        val swapTmpU = u
        u = v
        v = swapTmpU
    }

    u %= mod
    if (u < 0) {
        u += mod
    }
    return u
}

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