結果

問題 No.2 素因数ゲーム
ユーザー warashiwarashi
提出日時 2015-02-09 21:16:04
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,194 bytes
コンパイル時間 356 ms
コンパイル使用メモリ 10,976 KB
実行使用メモリ 70,604 KB
最終ジャッジ日時 2023-09-05 21:14:01
合計ジャッジ時間 7,162 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,216 KB
testcase_01 AC 17 ms
8,364 KB
testcase_02 AC 16 ms
8,324 KB
testcase_03 AC 16 ms
7,964 KB
testcase_04 AC 17 ms
8,224 KB
testcase_05 AC 16 ms
7,964 KB
testcase_06 AC 16 ms
8,272 KB
testcase_07 AC 18 ms
8,392 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3


def memoize(fn):
    table = {}

    def func(*args):
        if args not in table:
            table[args] = fn(*args)
        return table[args]
    return func


def prime():
    i = 2
    while True:
        if isPrime(i):
            yield(i)
        i += 1


@memoize
def isPrime(n):
    if n < 2:
        return False
    if n == 2:
        return True
    pg = prime()
    while True:
        p = next(pg)
        if p ** 2 > n:
            return True
        elif n % p == 0:
            return False


def prime_factorization(n):
    factor = {}
    pg = prime()
    while n > 1:
        p = next(pg)
        while n % p == 0:
            n = int(n / p)
            if p in factor:
                factor[p] += 1
            else:
                factor[p] = 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(sorted(tmp))):
                return False
    return True

N = int(input())
if nim(tuple(prime_factorization(N).values())):
    print("Bob")
else:
    print("Alice")
0