結果

問題 No.726 Tree Game
ユーザー Pump0129Pump0129
提出日時 2018-08-24 22:40:06
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 287 ms / 2,000 ms
コード長 1,133 bytes
コンパイル時間 12,945 ms
コンパイル使用メモリ 427,656 KB
実行使用メモリ 54,836 KB
最終ジャッジ日時 2023-08-13 00:20:58
合計ジャッジ時間 20,202 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 265 ms
53,132 KB
testcase_01 AC 272 ms
52,884 KB
testcase_02 AC 255 ms
53,072 KB
testcase_03 AC 260 ms
52,968 KB
testcase_04 AC 259 ms
52,848 KB
testcase_05 AC 265 ms
52,800 KB
testcase_06 AC 259 ms
52,856 KB
testcase_07 AC 266 ms
52,856 KB
testcase_08 AC 274 ms
52,900 KB
testcase_09 AC 269 ms
52,872 KB
testcase_10 AC 272 ms
52,952 KB
testcase_11 AC 258 ms
52,940 KB
testcase_12 AC 273 ms
53,052 KB
testcase_13 AC 263 ms
52,868 KB
testcase_14 AC 275 ms
52,844 KB
testcase_15 AC 271 ms
53,136 KB
testcase_16 AC 260 ms
53,052 KB
testcase_17 AC 275 ms
53,220 KB
testcase_18 AC 276 ms
52,964 KB
testcase_19 AC 274 ms
53,212 KB
testcase_20 AC 274 ms
54,836 KB
testcase_21 AC 287 ms
52,980 KB
testcase_22 AC 280 ms
52,844 KB
testcase_23 AC 270 ms
52,884 KB
testcase_24 AC 275 ms
53,092 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:20:10: warning: parameter 'args' is never used
fun main(args: Array<String>) {
         ^

ソースコード

diff #

package net.ipipip0129.kotlin.yukicoder

import kotlin.math.sqrt

private fun checkNumPrime(num: Long): Boolean {
    when {
        num == 1L -> return false
        num == 2L -> return true
        num % 2L == 0L -> return false
        else -> {
            val sqrtNum = sqrt(num.toDouble())
            for (i in 3..sqrtNum.toLong() step 2) {
                if (num % i == 0L) return false
            }
        }
    }
    return true
}

fun main(args: Array<String>) {
    val posList = readLine()!!.split(" ").map { it.toLong() }

    if (checkNumPrime(posList[0]) && checkNumPrime(posList[1])) {
        println("Second")
        return
    }

    var isFirst = true
    var npX = posList[1]
    var npY = posList[0]
    while (true) {
        if (!checkNumPrime(npY) && !checkNumPrime(npX + 1)) {
            npX += 1
        } else if (!checkNumPrime(npX) && !checkNumPrime(npY + 1)) {
            npY += 1
        } else {
            break
        }
        isFirst = !isFirst
    }
    if (!isFirst) {
        println("First")
    } else {
        println("Second")
    }
}
0