結果

問題 No.7 プライムナンバーゲーム
ユーザー Mao-betaMao-beta
提出日時 2024-02-28 00:42:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 72 ms / 5,000 ms
コード長 2,302 bytes
コンパイル時間 314 ms
コンパイル使用メモリ 81,828 KB
実行使用メモリ 66,284 KB
最終ジャッジ日時 2024-02-28 00:42:48
合計ジャッジ時間 2,442 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
63,928 KB
testcase_01 AC 53 ms
63,928 KB
testcase_02 AC 64 ms
66,280 KB
testcase_03 AC 58 ms
66,284 KB
testcase_04 AC 60 ms
66,284 KB
testcase_05 AC 59 ms
66,284 KB
testcase_06 AC 72 ms
66,280 KB
testcase_07 AC 62 ms
66,280 KB
testcase_08 AC 60 ms
66,280 KB
testcase_09 AC 62 ms
66,280 KB
testcase_10 AC 54 ms
63,928 KB
testcase_11 AC 60 ms
66,280 KB
testcase_12 AC 63 ms
66,280 KB
testcase_13 AC 62 ms
66,280 KB
testcase_14 AC 66 ms
66,280 KB
testcase_15 AC 64 ms
66,280 KB
testcase_16 AC 63 ms
66,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math
import bisect
from heapq import heapify, heappop, heappush
from collections import deque, defaultdict, Counter
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD99 = 998244353

input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
SMI = lambda: input().split()
SLI = lambda: list(SMI())
EI = lambda m: [NLI() for _ in range(m)]


# 高速エラストテネス sieve[n]はnの最小の素因数
def make_prime_table(n):
    sieve = list(range(n + 1))
    sieve[0] = -1
    sieve[1] = -1
    for i in range(4, n + 1, 2):
        sieve[i] = 2
    for i in range(3, int(n ** 0.5) + 1, 2):
        if sieve[i] != i:
            continue
        for j in range(i * i, n + 1, i * 2):
            if sieve[j] == j:
                sieve[j] = i
    return sieve

prime_table = make_prime_table(10001)


# 素因数分解 上のprime_tableと組み合わせて使う
def prime_factorize(n):
    result = []
    while n != 1:
        p = prime_table[n]
        e = 0
        while n % p == 0:
            n //= p
            e += 1
        result.append((p, e))
    return result


# Nの素因数分解を辞書で返す(単体)
def prime_fact(n):
    root = int(n**0.5) + 1
    prime_dict = {}
    for i in range(2, root):
        cnt = 0
        while n % i == 0:
            cnt += 1
            n = n // i
        if cnt:
            prime_dict[i] = cnt
    if n != 1:
        prime_dict[n] = 1
    return prime_dict

# 約数列挙(単体)
def divisors(x):
    res = set()
    for i in range(1, int(x**0.5) + 2):
        if x % i == 0:
            res.add(i)
            res.add(x//i)
    return res


def main():
    N = NI()
    # 素数列挙
    P = [p for i, p in enumerate(prime_table) if i == p and p <= N]
    dp = [0] * (N+1)
    dp[0] = 1
    dp[1] = 1
    for i in range(2, N+1):
        g = 0
        for p in P:
            if p > i:
                break
            if dp[i-p] == 0:
                g = 1
                break
        dp[i] = g
    if dp[N]:
        print("Win")
    else:
        print("Lose")


if __name__ == "__main__":
    main()
0