結果
| 問題 | No.103 素因数ゲーム リターンズ | 
| コンテスト | |
| ユーザー |  satama6 | 
| 提出日時 | 2022-10-19 02:46:13 | 
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 58 ms / 5,000 ms | 
| コード長 | 1,748 bytes | 
| コンパイル時間 | 159 ms | 
| コンパイル使用メモリ | 12,800 KB | 
| 実行使用メモリ | 11,136 KB | 
| 最終ジャッジ日時 | 2024-06-29 08:02:34 | 
| 合計ジャッジ時間 | 2,493 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 5 | 
| other | AC * 20 | 
ソースコード
class FastFactorization:
    """
    1 ~ Nの整数を全て素因数分解する O(N√N) -> O(NlogN)
    
    Parameters
    -----------
    N : int
        操作対象の上限値
    Notes
    -----------
    前処理にO(NloglogN), クエリでO(logN)    
    """
    def __init__(self, N):
        self.N = N
        self.min_factor = [0] * (N+1)
        self.__Eratosthenes()
    def __Eratosthenes(self):
        """
        前処理, O(NloglogN)
        """
        self.min_factor[1] = 1
        for p in range(2, self.N+1):
            if self.min_factor[p] : continue
            for q in range(p, self.N + 1, p):
                self.min_factor[q] = p
    # 高速素因数分解
    def factorize(self, n):
        """
        素因数分解を行う,O(logN)
        
        Parameters
        -----------
        n : int
            操作対象
        
        Returns
        -----------
        res : list(tuple[int, int])
            素因数、冪数を返す。
        """
        res = []
        while n > 1:
            p = self.min_factor[n]
            power = 0
            while n % p == 0:
                n //= p
                power += 1
            res.append((p, power))
        return res
N = int(input())
M = list(map(int, input().split()))
grundy = [0] * 10001
ff = FastFactorization(10001)
for i in range(2, 10001):
    tmp = set()
    factor = ff.factorize(i)
    for f, p in factor:
        if p > 1:
            tmp.add(grundy[i // f])
            tmp.add(grundy[i // f // f])
        else:
            tmp.add(grundy[i // f])
    
    g = 0
    while g in tmp:
        g += 1
    grundy[i] = g
nim = 0
for m in M:
    nim ^= grundy[m]
if nim:
    print('Alice')
else:
    print('Bob')
            
            
            
        