結果

問題 No.1224 I hate Sqrt Inequality
ユーザー rutilicusrutilicus
提出日時 2020-09-19 21:10:55
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 298 ms / 2,000 ms
コード長 1,290 bytes
コンパイル時間 15,798 ms
コンパイル使用メモリ 426,520 KB
実行使用メモリ 53,372 KB
最終ジャッジ日時 2023-09-05 23:23:48
合計ジャッジ時間 19,485 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 281 ms
53,044 KB
testcase_01 AC 279 ms
52,964 KB
testcase_02 AC 268 ms
52,880 KB
testcase_03 AC 272 ms
53,236 KB
testcase_04 AC 264 ms
53,076 KB
testcase_05 AC 263 ms
53,372 KB
testcase_06 AC 298 ms
53,220 KB
testcase_07 AC 267 ms
52,944 KB
testcase_08 AC 270 ms
53,044 KB
testcase_09 AC 273 ms
52,944 KB
testcase_10 AC 267 ms
52,944 KB
testcase_11 AC 263 ms
53,024 KB
testcase_12 AC 269 ms
52,956 KB
testcase_13 AC 275 ms
52,956 KB
testcase_14 AC 269 ms
53,056 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:42:13: 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(if (denominator != 1L) "Yes" else "No")
            ^

ソースコード

diff #

import kotlin.math.abs

data class Rational(val numerator: Long, val denominator: Long) {
    // 有理数クラス
    // 分子numerator, 分母denominator
    companion object Factory {
        private tailrec fun gcd(a: Long, b: Long): Long =
            when {
                b > a -> gcd(b, a)
                b == 0L -> a
                else -> gcd(b, a % b)
            }

        // 常に分子が正となるようなファクトリ
        fun create(numerator: Long, denominator: Long): Rational {
            val gcd = gcd(abs(numerator), abs(denominator))
            return if (numerator < 0) {
                Rational(numerator * -1L / gcd, denominator * -1L / gcd)
            } else {
                Rational(numerator / gcd, denominator / gcd)
            }
        }
    }
}

fun main() {
    val builder = StringBuilder()

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

    val rational = Rational.create(a, b)

    var denominator = rational.denominator

    while (denominator % 2L == 0L) {
        denominator /= 2L
    }
    while (denominator % 5L == 0L) {
        denominator /= 5L
    }

    builder.appendln(if (denominator != 1L) "Yes" else "No")

    print(builder.toString())
}

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