結果
| 問題 |
No.103 素因数ゲーム リターンズ
|
| コンテスト | |
| ユーザー |
terasa
|
| 提出日時 | 2022-09-26 21:08:34 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 61 ms / 5,000 ms |
| コード長 | 1,592 bytes |
| コンパイル時間 | 168 ms |
| コンパイル使用メモリ | 82,048 KB |
| 実行使用メモリ | 63,360 KB |
| 最終ジャッジ日時 | 2024-12-22 15:45:38 |
| 合計ジャッジ時間 | 2,504 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 20 |
ソースコード
from collections import deque
import sys
# import pypyjit
import itertools
import heapq
import math
from collections import deque, defaultdict
from functools import lru_cache
# for AtCoder Easy test
if __file__ == 'prog.py':
pass
else:
sys.setrecursionlimit(10 ** 6)
# pypyjit.set_param('max_unroll_recursion=-1')
input = sys.stdin.readline
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
@lru_cache(maxsize=None)
def grundy(n):
if n == 0:
return 0
S = set()
S.add(grundy(n - 1))
if n >= 2:
S.add(grundy(n - 2))
g = 0
while True:
if not g in S:
return g
g += 1
N = int(input())
M = readlist()
osa_k = Osa_k(10 ** 4)
acc = 0
for m in M:
D = defaultdict(int)
for f in osa_k.factors(m):
D[f] += 1
for v in D.values():
acc ^= grundy(v)
print('Alice' if acc > 0 else 'Bob')
terasa