結果
| 問題 | No.1243 約数加算 |
| コンテスト | |
| ユーザー |
rutilicus
|
| 提出日時 | 2020-10-16 10:16:04 |
| 言語 | Kotlin (2.3.20) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 950 bytes |
| 記録 | |
| コンパイル時間 | 9,100 ms |
| コンパイル使用メモリ | 443,212 KB |
| 最終ジャッジ日時 | 2026-04-03 02:22:17 |
| 合計ジャッジ時間 | 14,535 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge3_0 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
Main.kt:22:17: 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(ans.size + ansRev.size)
^^^^^^^^
Main.kt:26:17: error: 'fun StringBuilder.appendln(value: String?): 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(" "))
^^^^^^^^
ソースコード
fun main() {
val builder = StringBuilder()
val n = readInputLine().toInt()
repeat(n) {
var (a, b) = readInputLine().split(" ").map { it.toLong() }
val ans = mutableListOf<Long>()
val ansRev = mutableListOf<Long>()
while (a != b) {
val gcd = gcd(a, b)
if ((a / gcd) % 2L == 1L) {
ans.add(gcd)
a += gcd
} else {
ansRev.add(gcd)
b -= gcd
}
}
builder.appendln(ans.size + ansRev.size)
if (ans.isNotEmpty()) {
builder.append(ans.joinToString(" ") + " ")
}
builder.appendln(ansRev.reversed().joinToString(" "))
}
print(builder.toString())
}
fun readInputLine(): String {
return readLine()!!
}
tailrec fun gcd(a: Long, b: Long): Long =
when {
b > a -> gcd(b, a)
b == 0L -> a
else -> gcd(b, a % b)
}
rutilicus