結果

問題 No.816 Beautiful tuples
ユーザー rutilicusrutilicus
提出日時 2020-09-13 08:39:32
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 308 ms / 1,500 ms
コード長 726 bytes
コンパイル時間 15,471 ms
コンパイル使用メモリ 423,708 KB
実行使用メモリ 55,056 KB
最終ジャッジ日時 2023-09-02 08:44:38
合計ジャッジ時間 20,547 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 299 ms
52,744 KB
testcase_01 AC 301 ms
52,944 KB
testcase_02 AC 299 ms
52,832 KB
testcase_03 AC 302 ms
52,992 KB
testcase_04 AC 303 ms
53,156 KB
testcase_05 AC 302 ms
53,108 KB
testcase_06 AC 300 ms
53,100 KB
testcase_07 AC 301 ms
52,872 KB
testcase_08 AC 306 ms
52,780 KB
testcase_09 AC 305 ms
52,828 KB
testcase_10 AC 308 ms
55,056 KB
testcase_11 AC 301 ms
52,880 KB
testcase_12 AC 305 ms
52,916 KB
testcase_13 AC 306 ms
53,008 KB
testcase_14 AC 306 ms
52,928 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:26: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 ((a + b) % c == 0 && c != a && c != b) {
            if ((a + c) % b == 0 && (b + c) % a == 0) {
                ans = c
                break
            }
        }
        val c2 = (a + b) / c
        if ((a + b) % c2 == 0 && c2 != a && c2 != b) {
            if ((a + c2) % b == 0 && (b + c2) % a == 0) {
                ans = c2
                break
            }
        }
    }

    builder.appendln(ans)

    print(builder.toString())
}

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