結果

問題 No.7 プライムナンバーゲーム
ユーザー ckawatakckawatak
提出日時 2017-07-16 18:26:07
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,857 ms / 5,000 ms
コード長 735 bytes
コンパイル時間 153 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-04-09 04:22:02
合計ジャッジ時間 13,705 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
10,880 KB
testcase_01 AC 31 ms
10,880 KB
testcase_02 AC 1,838 ms
11,008 KB
testcase_03 AC 145 ms
10,880 KB
testcase_04 AC 60 ms
10,880 KB
testcase_05 AC 60 ms
11,008 KB
testcase_06 AC 561 ms
11,008 KB
testcase_07 AC 374 ms
10,880 KB
testcase_08 AC 188 ms
11,008 KB
testcase_09 AC 845 ms
11,008 KB
testcase_10 AC 30 ms
10,880 KB
testcase_11 AC 396 ms
11,136 KB
testcase_12 AC 1,323 ms
10,880 KB
testcase_13 AC 1,427 ms
11,008 KB
testcase_14 AC 1,857 ms
11,008 KB
testcase_15 AC 1,685 ms
11,008 KB
testcase_16 AC 1,607 ms
11,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())

from math import floor
from math import sqrt

def isprime(n):
    if n == 1:
        return False
    if n == 2:
        return True
    if n%2 == 0:
        return False
    for i in range(3, floor(sqrt(n))+1, 2):
        if i != n and n%i == 0:
            return False
    return True

def primes(n):
    p = []
    for i in range(n):
        if isprime(i):
            p.append(i)
    return p

ps = primes(n)

d = []
for i in range(n+1):
    d.append(0)

for i in range(4, n+1):
    s = set()
    for p in ps:
        if i - p < 2:
            break
        s.add(d[i-p])

    g = 0
    for j in sorted(s):
        if j != g:
            break
        g += 1

    d[i] = g

print('Win' if d[n] != 0 else 'Lose')
0