結果

問題 No.103 素因数ゲーム リターンズ
ユーザー satama6satama6
提出日時 2022-10-19 02:46:13
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 42 ms / 5,000 ms
コード長 1,748 bytes
コンパイル時間 183 ms
コンパイル使用メモリ 10,932 KB
実行使用メモリ 8,520 KB
最終ジャッジ日時 2023-09-11 18:08:13
合計ジャッジ時間 2,900 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
8,408 KB
testcase_01 AC 40 ms
8,392 KB
testcase_02 AC 38 ms
8,388 KB
testcase_03 AC 39 ms
8,388 KB
testcase_04 AC 39 ms
8,388 KB
testcase_05 AC 39 ms
8,292 KB
testcase_06 AC 38 ms
8,356 KB
testcase_07 AC 39 ms
8,480 KB
testcase_08 AC 42 ms
8,324 KB
testcase_09 AC 39 ms
8,292 KB
testcase_10 AC 40 ms
8,392 KB
testcase_11 AC 39 ms
8,360 KB
testcase_12 AC 39 ms
8,404 KB
testcase_13 AC 39 ms
8,468 KB
testcase_14 AC 39 ms
8,420 KB
testcase_15 AC 38 ms
8,348 KB
testcase_16 AC 38 ms
8,384 KB
testcase_17 AC 39 ms
8,344 KB
testcase_18 AC 39 ms
8,452 KB
testcase_19 AC 38 ms
8,408 KB
testcase_20 AC 38 ms
8,520 KB
testcase_21 AC 39 ms
8,364 KB
testcase_22 AC 39 ms
8,356 KB
testcase_23 AC 38 ms
8,400 KB
testcase_24 AC 40 ms
8,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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')
0