結果

問題 No.915 Plus Or Multiple Operation
コンテスト
ユーザー rutilicus
提出日時 2020-11-01 11:50:11
言語 Kotlin
(2.3.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 900 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 8,190 ms
コンパイル使用メモリ 414,732 KB
最終ジャッジ日時 2025-12-22 14:15:43
合計ジャッジ時間 8,963 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
Main.kt:12:21: error: 'fun StringBuilder.appendln(value: Int): 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(-1)
                    ^^^^^^^^
Main.kt:27:21: error: 'fun StringBuilder.appendln(value: Long): 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(ansCandidates.minOrNull()!! * b)
                    ^^^^^^^^

ソースコード

diff #
raw source code

fun main() {
    val builder = StringBuilder()

    val q = readInputLine().toInt()

    // 有志解説を読んでもよくわからない……

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

        if (c == 1L) {
            builder.appendln(-1)
        } else {
            var tmp = a
            var cnt = 0L
            val ansCandidates = mutableSetOf<Long>()
            while (tmp != 0L) {
                if (tmp % c == 0L) {
                    tmp /= c
                } else {
                    ansCandidates.add(cnt + (tmp + c - 2L) / (c - 1L))
                    tmp = tmp / c * c
                }
                cnt++
            }
            ansCandidates.add(cnt)
            builder.appendln(ansCandidates.minOrNull()!! * b)
        }
    }

    print(builder.toString())
}

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