結果

問題 No.103 素因数ゲーム リターンズ
ユーザー terasa
提出日時 2022-11-20 12:43:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 70 ms / 5,000 ms
コード長 1,539 bytes
コンパイル時間 271 ms
コンパイル使用メモリ 82,668 KB
実行使用メモリ 72,704 KB
最終ジャッジ日時 2024-09-21 13:17:14
合計ジャッジ時間 3,152 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

from typing import List, Tuple, Optional
import sys
import itertools
import heapq
import bisect
import math
from collections import deque, defaultdict
from functools import lru_cache, cmp_to_key

input = sys.stdin.readline

if __file__ != 'prog.py':
    sys.setrecursionlimit(10 ** 6)


def readints(): return map(int, input().split())
def readlist(): return list(readints())
def readstr(): return input()[:-1]


class Osa_k:
    # N以下の整数を素因数分解 O(NlogN)
    def __init__(self, N):
        self.min_factor = [i for i in range(N + 1)]
        for i in range(2, N + 1):
            if i * i > N:
                break
            if self.min_factor[i] == i:
                for j in range(2, N + 1):
                    if i * j > N:
                        break
                    if self.min_factor[i * j] > i:
                        self.min_factor[i * j] = i

    def factors(self, n):
        f = []
        while n > 1:
            f.append(self.min_factor[n])
            n //= self.min_factor[n]
        return f


N = int(input())
M = readlist()
L = 10 ** 4
osa_k = Osa_k(10 ** 4)


@lru_cache(None)
def grundy(n):
    if n == 1:
        return 0
    cnt = defaultdict(int)
    for f in osa_k.factors(n):
        cnt[f] += 1
    S = set()
    for k, v in cnt.items():
        S.add(grundy(n // k))
        if v > 1:
            S.add(grundy(n // (k * k)))
    for i in range(L + 10):
        if i not in S:
            return i


acc = 0
for m in M:
    acc ^= grundy(m)
print('Alice' if acc > 0 else 'Bob')
0