結果

問題 No.7 プライムナンバーゲーム
ユーザー masumasumath1masumasumath1
提出日時 2019-11-30 10:22:34
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 839 bytes
コンパイル時間 337 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-05-01 01:48:30
合計ジャッジ時間 1,739 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
10,752 KB
testcase_01 WA -
testcase_02 AC 48 ms
10,880 KB
testcase_03 AC 33 ms
10,752 KB
testcase_04 AC 31 ms
10,752 KB
testcase_05 WA -
testcase_06 AC 38 ms
10,880 KB
testcase_07 AC 35 ms
10,752 KB
testcase_08 AC 33 ms
10,752 KB
testcase_09 WA -
testcase_10 AC 29 ms
10,880 KB
testcase_11 AC 36 ms
10,880 KB
testcase_12 AC 43 ms
10,880 KB
testcase_13 AC 45 ms
10,880 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 46 ms
10,880 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