結果

問題 No.1243 約数加算
ユーザー rutilicusrutilicus
提出日時 2020-10-16 09:48:04
言語 Kotlin
(1.9.23)
結果
TLE  
実行時間 -
コード長 1,041 bytes
コンパイル時間 13,715 ms
コンパイル使用メモリ 423,072 KB
実行使用メモリ 55,040 KB
最終ジャッジ日時 2023-09-28 01:46:11
合計ジャッジ時間 21,135 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 283 ms
53,228 KB
testcase_01 AC 279 ms
52,876 KB
testcase_02 AC 282 ms
52,928 KB
testcase_03 AC 307 ms
54,616 KB
testcase_04 AC 366 ms
55,040 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:33:17: warning: 'appendln(Int): 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(ansRev.size)
                ^
Main.kt:34:17: warning: 'appendln(String?): 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(ansRev.reversed().joinToString(" "))
                ^

ソースコード

diff #

fun main() {
    val builder = StringBuilder()

    val n = readInputLine().toInt()

    repeat(n) {
        val (a, b) = readInputLine().split(" ").map { it.toLong() }
        val ansRev = mutableListOf<Long>()

        var current = b

        while (current != a) {
            var maxDiv = 1L
            for (i in LongRange(1L, current)) {
                if (i * i > current || current - i < a) {
                    break
                }
                if (current % i != 0L) {
                    continue
                }
                if (current - i >= a) {
                    maxDiv = i
                }
                if (current - current / i >= a) {
                    maxDiv = current / i
                    break
                }
            }
            ansRev.add(maxDiv)
            current -= maxDiv
        }

        builder.appendln(ansRev.size)
        builder.appendln(ansRev.reversed().joinToString(" "))
    }

    print(builder.toString())
}

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