結果

問題 No.103 素因数ゲーム リターンズ
ユーザー terasaterasa
提出日時 2022-11-20 12:43:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 80 ms / 5,000 ms
コード長 1,539 bytes
コンパイル時間 164 ms
コンパイル使用メモリ 81,628 KB
実行使用メモリ 72,696 KB
最終ジャッジ日時 2023-10-21 12:00:02
合計ジャッジ時間 3,369 ms
ジャッジサーバーID
(参考情報)
judge10 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
70,636 KB
testcase_01 AC 73 ms
70,636 KB
testcase_02 AC 75 ms
70,636 KB
testcase_03 AC 73 ms
70,640 KB
testcase_04 AC 73 ms
70,636 KB
testcase_05 AC 73 ms
70,636 KB
testcase_06 AC 74 ms
70,640 KB
testcase_07 AC 74 ms
70,636 KB
testcase_08 AC 74 ms
70,636 KB
testcase_09 AC 74 ms
70,636 KB
testcase_10 AC 76 ms
70,636 KB
testcase_11 AC 74 ms
70,640 KB
testcase_12 AC 77 ms
72,688 KB
testcase_13 AC 77 ms
70,640 KB
testcase_14 AC 77 ms
72,688 KB
testcase_15 AC 80 ms
72,688 KB
testcase_16 AC 76 ms
70,640 KB
testcase_17 AC 80 ms
72,688 KB
testcase_18 AC 76 ms
70,640 KB
testcase_19 AC 80 ms
72,696 KB
testcase_20 AC 76 ms
70,640 KB
testcase_21 AC 78 ms
72,688 KB
testcase_22 AC 76 ms
70,640 KB
testcase_23 AC 76 ms
70,640 KB
testcase_24 AC 74 ms
70,640 KB
権限があれば一括ダウンロードができます

ソースコード

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