結果

問題 No.673 カブトムシ
ユーザー rutilicusrutilicus
提出日時 2020-12-20 11:27:04
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 1,240 bytes
コンパイル時間 13,838 ms
コンパイル使用メモリ 441,132 KB
実行使用メモリ 54,584 KB
最終ジャッジ日時 2023-10-21 10:33:03
合計ジャッジ時間 20,820 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 317 ms
54,536 KB
testcase_03 AC 311 ms
54,540 KB
testcase_04 AC 312 ms
54,540 KB
testcase_05 AC 312 ms
54,540 KB
testcase_06 AC 318 ms
54,540 KB
testcase_07 AC 318 ms
54,544 KB
testcase_08 AC 315 ms
54,524 KB
testcase_09 AC 311 ms
54,540 KB
testcase_10 AC 312 ms
54,548 KB
testcase_11 AC 314 ms
54,540 KB
testcase_12 AC 311 ms
54,524 KB
testcase_13 AC 313 ms
54,528 KB
testcase_14 AC 312 ms
54,544 KB
testcase_15 AC 314 ms
54,528 KB
testcase_16 AC 316 ms
54,524 KB
testcase_17 AC 313 ms
54,540 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 % mod) * (d % mod) % 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 % mod) * (d % mod) % 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