結果
問題 | No.103 素因数ゲーム リターンズ |
ユーザー |
|
提出日時 | 2015-07-17 19:32:14 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 28 ms / 5,000 ms |
コード長 | 859 bytes |
コンパイル時間 | 100 ms |
コンパイル使用メモリ | 12,416 KB |
実行使用メモリ | 10,880 KB |
最終ジャッジ日時 | 2024-07-08 08:25:57 |
合計ジャッジ時間 | 1,541 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 20 |
ソースコード
import collections import math def factorize(n): ''' returns a list of prime factors of n. ex. factorize(24) = [2, 2, 2, 3] source: Rossetta code: prime factorization (slightly modified) http://rosettacode.org/wiki/Prime_decomposition#Python:_Using_floating_point ''' step = lambda x: 1 + (x<<2) - ((x>>1)<<1) maxq = int(math.floor(math.sqrt(n))) d = 1 q = n % 2 == 0 and 2 or 3 while q <= maxq and n % q != 0: q = step(d) d += 1 return q <= maxq and [q] + factorize(n//q) or [n] def solve(N, Ms): piles = [] for m in Ms: piles.extend(collections.Counter(factorize(m)).values()) c = piles[0] % 3 for p in piles[1:]: c ^= p % 3 if c == 0: print('Bob') else: print('Alice') N = int(input()) Ms = list(map(int, input().split())) solve(N, Ms)