結果

問題 No.7 プライムナンバーゲーム
ユーザー masumasumath1masumasumath1
提出日時 2019-11-30 10:51:35
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 792 ms / 5,000 ms
コード長 895 bytes
コンパイル時間 143 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-04-09 04:46:46
合計ジャッジ時間 6,300 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,752 KB
testcase_01 AC 30 ms
10,752 KB
testcase_02 AC 792 ms
10,880 KB
testcase_03 AC 75 ms
10,752 KB
testcase_04 AC 39 ms
10,752 KB
testcase_05 AC 39 ms
10,752 KB
testcase_06 AC 243 ms
10,752 KB
testcase_07 AC 169 ms
10,752 KB
testcase_08 AC 91 ms
10,752 KB
testcase_09 AC 347 ms
10,752 KB
testcase_10 AC 29 ms
10,880 KB
testcase_11 AC 177 ms
10,752 KB
testcase_12 AC 564 ms
10,880 KB
testcase_13 AC 577 ms
10,880 KB
testcase_14 AC 742 ms
10,880 KB
testcase_15 AC 702 ms
10,880 KB
testcase_16 AC 683 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(2,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