結果

問題 No.1281 Cigarette Distribution
ユーザー rutilicusrutilicus
提出日時 2020-11-07 21:54:37
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 509 ms / 2,000 ms
コード長 828 bytes
コンパイル時間 12,692 ms
コンパイル使用メモリ 425,332 KB
実行使用メモリ 56,556 KB
最終ジャッジ日時 2023-09-29 20:55:12
合計ジャッジ時間 20,973 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 273 ms
53,016 KB
testcase_01 AC 273 ms
53,140 KB
testcase_02 AC 267 ms
52,968 KB
testcase_03 AC 283 ms
53,012 KB
testcase_04 AC 279 ms
53,008 KB
testcase_05 AC 273 ms
53,136 KB
testcase_06 AC 278 ms
53,064 KB
testcase_07 AC 269 ms
53,092 KB
testcase_08 AC 267 ms
52,936 KB
testcase_09 AC 263 ms
53,040 KB
testcase_10 AC 272 ms
52,960 KB
testcase_11 AC 275 ms
53,036 KB
testcase_12 AC 380 ms
56,272 KB
testcase_13 AC 445 ms
56,304 KB
testcase_14 AC 409 ms
56,276 KB
testcase_15 AC 380 ms
56,236 KB
testcase_16 AC 394 ms
56,364 KB
testcase_17 AC 281 ms
53,208 KB
testcase_18 AC 503 ms
56,380 KB
testcase_19 AC 498 ms
56,556 KB
testcase_20 AC 509 ms
56,344 KB
testcase_21 AC 426 ms
56,352 KB
testcase_22 AC 448 ms
56,244 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:14: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(pow(moreNum, moreBox, mod) * pow(lessNum, lessBox, mod) % mod * (lessNum - 1L) % mod)
                ^

ソースコード

diff #

fun main() {
    val builder = StringBuilder()

    // 解説読んだ
    val mod = 1000000007L

    val (n, m) = readInputLine().split(" ").map { it.toLong() }

    for (i in LongRange(1L, m)) {
        val moreNum = (n + 1L) / i + 1L
        val lessNum = moreNum - 1L
        val moreBox = (n + 1L) % i
        val lessBox = i - moreBox - 1L
        builder.appendln(pow(moreNum, moreBox, mod) * pow(lessNum, lessBox, mod) % mod * (lessNum - 1L) % mod)
    }

    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