結果

問題 No.103 素因数ゲーム リターンズ
ユーザー rpy3cpprpy3cpp
提出日時 2015-07-17 19:32:14
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 20 ms / 5,000 ms
コード長 859 bytes
コンパイル時間 137 ms
コンパイル使用メモリ 10,992 KB
実行使用メモリ 8,784 KB
最終ジャッジ日時 2023-09-22 17:00:22
合計ジャッジ時間 2,025 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,740 KB
testcase_01 AC 19 ms
8,784 KB
testcase_02 AC 19 ms
8,604 KB
testcase_03 AC 19 ms
8,736 KB
testcase_04 AC 19 ms
8,740 KB
testcase_05 AC 18 ms
8,640 KB
testcase_06 AC 19 ms
8,636 KB
testcase_07 AC 19 ms
8,692 KB
testcase_08 AC 19 ms
8,560 KB
testcase_09 AC 19 ms
8,748 KB
testcase_10 AC 19 ms
8,744 KB
testcase_11 AC 19 ms
8,596 KB
testcase_12 AC 20 ms
8,560 KB
testcase_13 AC 19 ms
8,732 KB
testcase_14 AC 19 ms
8,564 KB
testcase_15 AC 19 ms
8,784 KB
testcase_16 AC 19 ms
8,608 KB
testcase_17 AC 20 ms
8,600 KB
testcase_18 AC 19 ms
8,732 KB
testcase_19 AC 19 ms
8,648 KB
testcase_20 AC 19 ms
8,700 KB
testcase_21 AC 19 ms
8,656 KB
testcase_22 AC 19 ms
8,732 KB
testcase_23 AC 19 ms
8,784 KB
testcase_24 AC 20 ms
8,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0