結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
10,880 KB
testcase_01 WA -
testcase_02 AC 706 ms
10,880 KB
testcase_03 AC 68 ms
10,752 KB
testcase_04 AC 36 ms
10,880 KB
testcase_05 WA -
testcase_06 AC 218 ms
10,752 KB
testcase_07 AC 169 ms
10,752 KB
testcase_08 AC 86 ms
10,880 KB
testcase_09 WA -
testcase_10 AC 26 ms
10,880 KB
testcase_11 AC 160 ms
10,752 KB
testcase_12 AC 498 ms
10,880 KB
testcase_13 AC 550 ms
10,880 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 604 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
#n以下の素数列挙
def mkP_tridiv(n):
    for i in range(n+1):
        if isPrime(i):
            P.append(i)

N = int(input())
#N以下の素数をPに格納
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 not A[i-p]:
            A[i] = True
            break
        else:
            A[i] = False
if A[N]:
    print("Win")
else:
    print("Lose")
0