結果

問題 No.7 プライムナンバーゲーム
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2022-11-28 08:15:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 234 ms / 5,000 ms
コード長 1,550 bytes
コンパイル時間 282 ms
コンパイル使用メモリ 82,436 KB
実行使用メモリ 79,752 KB
最終ジャッジ日時 2024-04-15 10:20:20
合計ジャッジ時間 3,538 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
68,164 KB
testcase_01 AC 64 ms
68,852 KB
testcase_02 AC 234 ms
79,348 KB
testcase_03 AC 98 ms
79,272 KB
testcase_04 AC 88 ms
79,264 KB
testcase_05 AC 85 ms
79,404 KB
testcase_06 AC 130 ms
79,340 KB
testcase_07 AC 117 ms
79,364 KB
testcase_08 AC 103 ms
79,304 KB
testcase_09 AC 150 ms
79,260 KB
testcase_10 AC 65 ms
69,372 KB
testcase_11 AC 118 ms
79,336 KB
testcase_12 AC 188 ms
79,752 KB
testcase_13 AC 193 ms
79,360 KB
testcase_14 AC 225 ms
79,472 KB
testcase_15 AC 220 ms
79,608 KB
testcase_16 AC 211 ms
79,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# import pypyjit
# pypyjit.set_param('max_unroll_recursion=-1')
from collections import *
from functools import *
from itertools import *
from heapq import *
import sys,math

input = sys.stdin.readline

N = int(input())
class prime_factorize():
    
    def __init__(self,M=10**6):
        self.sieve = [-1]*(M+1)
        self.sieve[1] = 1
        self.p = [False]*(M+1)
        self.mu = [1]*(M+1)
        
        for i in range(2,M+1):
            if self.sieve[i] == -1:
                self.p[i] = True
                
                i2 = i**2
                for j in range(i2,M+1,i2):
                    
                    self.mu[j] = 0
                
                
                for j in range(i,M+1,i):
                    self.sieve[j] = i
                    
                    self.mu[j] *= -1
                    
    def factors(self,x):
        tmp = []
        while self.sieve[x] != x:
            tmp.append(self.sieve[x])
            x //= self.sieve[x]
        tmp.append(self.sieve[x])
        return tmp
        
    def is_prime(self,x):
        return self.p[x]
        
    def mobius(self,x):
        return self.mu[x]
        
pf = prime_factorize(100010)

dp = [False]*(N+1)
plist = []
for i in range(2,N+1):
    if pf.is_prime(i):
        plist.append(i)

dp[0]=True
dp[1]=True
    

for i in range(2,N+1):
    

    cnd = []
    for p in plist:
        if i-p>=0:
            cnd.append(i-p)
    
    if any(dp[c]==False for c in cnd):
        dp[i]=True
if dp[N]:
    print('Win')
else:
    print('Lose')
0