結果

問題 No.816 Beautiful tuples
ユーザー rutilicus
提出日時 2020-09-13 08:37:00
言語 Kotlin
(2.1.0)
結果
WA  
実行時間 -
コード長 556 bytes
コンパイル時間 13,513 ms
コンパイル使用メモリ 433,364 KB
実行使用メモリ 55,580 KB
最終ジャッジ日時 2024-06-11 15:34:01
合計ジャッジ時間 19,499 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 7 WA * 8
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:22:13: 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(ans)
            ^

ソースコード

diff #

import kotlin.math.sqrt

fun main() {
    val builder = StringBuilder()

    val (a, b) = readInputLine().split(" ").map { it.toInt() }

    var ans = -1

    for (c in 1..sqrt((a + b).toDouble()).toInt() + 1) {
        if (c == a || c == b) {
            continue
        }
        if ((a + b) % c == 0) {
            if ((a + c) % b == 0 && (b + c) % a == 0) {
                ans = c
                break
            }
        }
    }

    builder.appendln(ans)

    print(builder.toString())
}

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