結果
問題 |
No.103 素因数ゲーム リターンズ
|
ユーザー |
|
提出日時 | 2015-02-11 02:18:51 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 895 ms / 5,000 ms |
コード長 | 1,274 bytes |
コンパイル時間 | 331 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 19,200 KB |
最終ジャッジ日時 | 2024-06-23 18:29:07 |
合計ジャッジ時間 | 3,545 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 20 |
ソースコード
#!/usr/bin/env python3 from collections import defaultdict from functools import lru_cache from itertools import count, takewhile def prime(): prime = [] def _isPrime(n): for d in takewhile(lambda x: x * x <= n, prime): if n % d == 0: return False return True for i in count(2): if _isPrime(i): prime.append(i) yield(i) @lru_cache(maxsize=None) def prime_factorization(n): factor = defaultdict(int) for p in takewhile(lambda x: x * x <= n, prime()): while n % p == 0: n //= p factor[p] += 1 if n > 1: factor[n] += 1 return factor @lru_cache(maxsize=None) def nim(nums): if sum(nums) == 0: True for i in range(len(nums)): for j in (2, 1): if nums[i] < j: continue tmp = list(nums) tmp[i] -= j tmp.sort(reverse=True) if nim(tuple(tmp)): return False return True N = int(input()) M = [int(x) for x in input().split()] init = [] for m in M: init.extend(prime_factorization(m).values()) init = [x % 3 for x in init] init.sort(reverse=True) if nim(tuple(init)): print("Bob") else: print("Alice")