結果
| 問題 | No.2 素因数ゲーム | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2015-02-09 21:35:05 | 
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 32 ms / 5,000 ms | 
| コード長 | 833 bytes | 
| コンパイル時間 | 465 ms | 
| コンパイル使用メモリ | 12,544 KB | 
| 実行使用メモリ | 10,752 KB | 
| 最終ジャッジ日時 | 2024-12-26 10:56:29 | 
| 合計ジャッジ時間 | 2,462 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 31 | 
ソースコード
#!/usr/bin/env python3
from collections import defaultdict
def memoize(fn):
    table = {}
    def func(*args):
        if args not in table:
            table[args] = fn(*args)
        return table[args]
    return func
def prime_factorization(n):
    factor = defaultdict(int)
    i = 2
    while i * i <= n:
        while n % i == 0:
            n = n // i
            factor[i] += 1
        i += 1
    if n > 1:
        factor[n] += 1
    return factor
@memoize
def nim(nums):
    if sum(nums) == 0:
        True
    for i in range(len(nums)):
        for n in range(1, nums[i] + 1):
            tmp = list(nums)
            tmp[i] -= n
            if nim(tuple(tmp)):
                return False
    return True
N = int(input())
if nim(tuple(prime_factorization(N).values())):
    print("Bob")
else:
    print("Alice")
            
            
            
        