結果

問題 No.1243 約数加算
ユーザー rutilicus
提出日時 2020-10-16 09:48:04
言語 Kotlin
(2.1.0)
結果
TLE  
実行時間 -
コード長 1,041 bytes
コンパイル時間 16,619 ms
コンパイル使用メモリ 436,544 KB
実行使用メモリ 87,668 KB
最終ジャッジ日時 2024-07-20 20:22:54
合計ジャッジ時間 20,701 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 4 TLE * 1 -- * 4
権限があれば一括ダウンロードができます
コンパイルメッセージ
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