結果

問題 No.2 素因数ゲーム
ユーザー nanaenanae
提出日時 2017-04-10 19:10:34
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 21 ms / 5,000 ms
コード長 764 bytes
コンパイル時間 93 ms
コンパイル使用メモリ 10,936 KB
実行使用メモリ 8,776 KB
最終ジャッジ日時 2023-08-27 04:39:05
合計ジャッジ時間 2,057 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
8,776 KB
testcase_01 AC 20 ms
8,736 KB
testcase_02 AC 19 ms
8,636 KB
testcase_03 AC 20 ms
8,596 KB
testcase_04 AC 21 ms
8,704 KB
testcase_05 AC 20 ms
8,572 KB
testcase_06 AC 20 ms
8,732 KB
testcase_07 AC 20 ms
8,540 KB
testcase_08 AC 19 ms
8,772 KB
testcase_09 AC 20 ms
8,556 KB
testcase_10 AC 21 ms
8,700 KB
testcase_11 AC 21 ms
8,564 KB
testcase_12 AC 21 ms
8,608 KB
testcase_13 AC 21 ms
8,760 KB
testcase_14 AC 20 ms
8,696 KB
testcase_15 AC 21 ms
8,576 KB
testcase_16 AC 20 ms
8,744 KB
testcase_17 AC 20 ms
8,560 KB
testcase_18 AC 21 ms
8,612 KB
testcase_19 AC 21 ms
8,600 KB
testcase_20 AC 21 ms
8,736 KB
testcase_21 AC 21 ms
8,704 KB
testcase_22 AC 21 ms
8,556 KB
testcase_23 AC 20 ms
8,696 KB
testcase_24 AC 21 ms
8,740 KB
testcase_25 AC 21 ms
8,704 KB
testcase_26 AC 21 ms
8,632 KB
testcase_27 AC 21 ms
8,552 KB
testcase_28 AC 21 ms
8,636 KB
testcase_29 AC 21 ms
8,540 KB
testcase_30 AC 21 ms
8,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from functools import lru_cache
import sys

sys.setrecursionlimit(10**7)

def solve():
    @lru_cache(maxsize=None)
    def memo_rec(m):
        if m == 1:
            return False

        res = False

        for p in p_divs:
            i = 1
            while m % (p**i) == 0:
                res |= not memo_rec(m // (p**i))
                i += 1

        # print(m, res)
        return res

    N = int(input())

    p_divs = []

    m = N

    for p in range(2, N):
        if p*p > N:
            break

        if m % p == 0:
            p_divs.append(p)

            while m % p == 0:
                m //= p

    if m > 1:
        p_divs.append(m)

    judge = memo_rec(N)

    print('Alice' if judge else 'Bob')

if __name__ == '__main__':
    solve()
0