結果

問題 No.7 プライムナンバーゲーム
ユーザー DialBirdDialBird
提出日時 2017-03-12 14:43:24
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 147 ms / 5,000 ms
コード長 767 bytes
コンパイル時間 189 ms
コンパイル使用メモリ 10,888 KB
実行使用メモリ 9,112 KB
最終ジャッジ日時 2023-07-24 20:48:06
合計ジャッジ時間 2,128 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,956 KB
testcase_01 AC 15 ms
7,996 KB
testcase_02 AC 147 ms
8,976 KB
testcase_03 AC 23 ms
8,448 KB
testcase_04 AC 16 ms
7,948 KB
testcase_05 AC 17 ms
7,948 KB
testcase_06 AC 54 ms
8,588 KB
testcase_07 AC 49 ms
8,584 KB
testcase_08 AC 26 ms
8,588 KB
testcase_09 AC 78 ms
9,052 KB
testcase_10 AC 14 ms
7,948 KB
testcase_11 AC 43 ms
8,588 KB
testcase_12 AC 121 ms
9,060 KB
testcase_13 AC 119 ms
9,112 KB
testcase_14 AC 144 ms
9,000 KB
testcase_15 AC 142 ms
8,996 KB
testcase_16 AC 134 ms
9,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import sqrt

class Yukicoder:
    def __init__(self):
        self.n = int(input())

    def run(self):
        dp = set([0,1])
        primes = set([])
        for i in range(2, self.n + 1):
            if self.prime_check(i):
                primes.add(i)
            for j in primes:
                if (i - j) not in dp:
                    dp.add(i)
                    break
        if self.n in dp:
            return "Win"
        else:
            return "Lose"

    
    def prime_check(self, n):
        if n < 2:
            return False
        else:
            i = 2
            while i <= sqrt(n):
                if n % i == 0:
                    return False
                i += 1
            return True


y = Yukicoder()
print(y.run())
0