結果

問題 No.7 プライムナンバーゲーム
ユーザー masumasumath1masumasumath1
提出日時 2019-11-30 10:22:34
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 839 bytes
コンパイル時間 166 ms
コンパイル使用メモリ 10,912 KB
実行使用メモリ 8,472 KB
最終ジャッジ日時 2023-08-13 08:07:39
合計ジャッジ時間 2,039 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,948 KB
testcase_01 WA -
testcase_02 AC 32 ms
8,328 KB
testcase_03 AC 19 ms
7,800 KB
testcase_04 AC 16 ms
7,872 KB
testcase_05 WA -
testcase_06 AC 24 ms
7,936 KB
testcase_07 AC 22 ms
7,908 KB
testcase_08 AC 20 ms
7,908 KB
testcase_09 WA -
testcase_10 AC 16 ms
7,960 KB
testcase_11 AC 22 ms
7,912 KB
testcase_12 AC 29 ms
8,436 KB
testcase_13 AC 30 ms
8,356 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 31 ms
8,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def isPrime(n):
    if n < 2:
        return False
    for i in range(2,n):
        #iはsqrt(n)まで調べれば十分
        if i*i > n:
            break
        #一度でもiで割り切れたら素数ではない
        if n%i == 0:
            return False
    #forを抜けたら素数
    return True

def mkP_tridiv(n):
    for i in range(n+1):
        if isPrime(i):
            P.append(i)



N = int(input())
P = []
mkP_tridiv(N)
#数字iで回ってきたときに自分が勝てるかどうか
#勝てるTrue,負けるFalse
A = [ False for i in range(N+1)]
#0,1で回ってきたら勝ちとする
A[0],A[1] = True,True
for i in range(1,N+1):
    for p in P:
        if i-p >= 0 and A[i-p]:
            A[i] = True
            break
        else:
            A[i] = False
if A[N]:
    print("Win")
else:
    print("Lose")
0