結果

問題 No.2 素因数ゲーム
ユーザー kaoru muratakaoru murata
提出日時 2021-08-26 01:22:56
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 18 ms / 5,000 ms
コード長 1,896 bytes
コンパイル時間 112 ms
コンパイル使用メモリ 10,820 KB
実行使用メモリ 8,344 KB
最終ジャッジ日時 2023-08-10 23:30:07
合計ジャッジ時間 2,186 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,104 KB
testcase_01 AC 17 ms
8,188 KB
testcase_02 AC 16 ms
8,344 KB
testcase_03 AC 16 ms
8,220 KB
testcase_04 AC 16 ms
8,288 KB
testcase_05 AC 16 ms
8,204 KB
testcase_06 AC 17 ms
8,136 KB
testcase_07 AC 17 ms
8,188 KB
testcase_08 AC 16 ms
8,160 KB
testcase_09 AC 17 ms
8,188 KB
testcase_10 AC 16 ms
8,284 KB
testcase_11 AC 16 ms
8,172 KB
testcase_12 AC 16 ms
8,288 KB
testcase_13 AC 16 ms
8,224 KB
testcase_14 AC 16 ms
8,176 KB
testcase_15 AC 17 ms
8,192 KB
testcase_16 AC 17 ms
8,196 KB
testcase_17 AC 16 ms
8,264 KB
testcase_18 AC 17 ms
8,140 KB
testcase_19 AC 17 ms
8,192 KB
testcase_20 AC 16 ms
8,152 KB
testcase_21 AC 17 ms
8,288 KB
testcase_22 AC 17 ms
8,224 KB
testcase_23 AC 16 ms
8,212 KB
testcase_24 AC 17 ms
8,216 KB
testcase_25 AC 16 ms
8,332 KB
testcase_26 AC 16 ms
8,104 KB
testcase_27 AC 16 ms
8,220 KB
testcase_28 AC 16 ms
8,152 KB
testcase_29 AC 15 ms
8,156 KB
testcase_30 AC 16 ms
8,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd


def is_prime(n):
    if n in {2, 3, 5, 7, 11, 13, 17}:
        return True
    d = n - 1
    d = d // (d & -d)
    L = (
        [2, 7, 61]
        if n < 1 << 32
        else [2, 3, 5, 7, 11, 13, 17]
        if n < 1 << 48
        else [2, 325, 9375, 28178, 450775, 9780504, 1795265022]
    )
    for a in L:
        t = d
        y = pow(a, t, n)
        if y == 1:
            continue
        while y != n - 1:
            y = (y * y) % n
            if y == 1 or t == n - 1:
                return False
            t <<= 1
    return True


def pollard_brent_rho(n):
    m = 1 << n.bit_length() // 8 + 1
    for c in range(1, 99):
        def f(x): return (x * x + c) % n
        y, r, q, g = 2, 1, 1, 1
        while g == 1:
            x = y
            for i in range(r):
                y = f(y)
            k = 0
            while k < r and g == 1:
                for i in range(min(m, r - k)):
                    y = f(y)
                    q = q * abs(x - y) % n
                g = gcd(q, n)
                k += m
            r <<= 1
        if g < n:
            if is_prime(g):
                return g
            elif is_prime(n // g):
                return n // g


def factorize(n):
    i = 2
    ret = {}
    while i * i <= n:
        k = 0
        while n % i == 0:
            n //= i
            k += 1
        if k:
            ret[i] = k
        i += 1 + i % 2
        if i != 101 or n < 2 ** 20:
            continue
        while n > 1:
            if is_prime(n):
                ret[n], n = 1, 1
                continue
            j = pollard_brent_rho(n)
            k = 0
            while n % j == 0:
                n //= j
                k += 1
            ret[j] = k

    if n > 1:
        ret[n] = 1
    return ret


N = int(input())
pf = factorize(N)
res = 0
for v in pf.values():
    res ^= v
print('Alice' if res else 'Bob')
0