結果
| 問題 | No.103 素因数ゲーム リターンズ |
| コンテスト | |
| ユーザー |
terasa
|
| 提出日時 | 2022-09-26 21:04:44 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,580 bytes |
| コンパイル時間 | 175 ms |
| コンパイル使用メモリ | 82,176 KB |
| 実行使用メモリ | 64,384 KB |
| 最終ジャッジ日時 | 2024-12-22 15:45:32 |
| 合計ジャッジ時間 | 2,747 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 12 WA * 8 |
ソースコード
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)
D = defaultdict(int)
for m in M:
for f in osa_k.factors(m):
D[f] += 1
acc = 0
for v in D.values():
acc ^= grundy(v)
print('Alice' if acc > 0 else 'Bob')
terasa