結果

問題 No.103 素因数ゲーム リターンズ
ユーザー mkawa2
提出日時 2020-01-16 16:18:11
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 32 ms / 5,000 ms
コード長 945 bytes
コンパイル時間 151 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-06-23 20:50:04
合計ジャッジ時間 1,752 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10 ** 6)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))

# 素因数分解して指数だけのリストを返す関数
def exps(x):
    if x < 3: return [1]
    res = []
    x0 = x
    for d in range(2, x0):
        if d ** 2 > x:
            if x > 1: res.append(1)
            return res
        cnt = 0
        while x % d == 0:
            x //= d
            cnt += 1
        if cnt: res.append(cnt)

def main():
    n = II()
    mm = LI()
    g = 0
    for m in mm:
        # 整数mのGrundy数を求める
        # 指数の mod 3 が素因数ごとのGrundy数なので
        # そのxor和をとったものが整数mのGrundy数
        ee = exps(m)
        gm = 0
        for e in ee: gm ^= e % 3
        # 整数mのGrundy数のxor和をとると、全体のGrundy数
        g^=gm
    if g:print("Alice")
    else:print("Bob")

main()
0