結果

問題 No.2576 LCM Pattern
ユーザー 👑 rin204rin204
提出日時 2023-12-04 19:58:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 2,181 bytes
コンパイル時間 413 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 53,844 KB
最終ジャッジ日時 2023-12-04 19:58:13
合計ジャッジ時間 2,347 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,588 KB
testcase_01 AC 38 ms
53,844 KB
testcase_02 AC 37 ms
53,844 KB
testcase_03 AC 38 ms
53,588 KB
testcase_04 AC 36 ms
53,588 KB
testcase_05 AC 37 ms
53,844 KB
testcase_06 AC 37 ms
53,844 KB
testcase_07 AC 38 ms
53,588 KB
testcase_08 AC 38 ms
53,844 KB
testcase_09 AC 36 ms
53,588 KB
testcase_10 AC 37 ms
53,844 KB
testcase_11 AC 38 ms
53,844 KB
testcase_12 AC 37 ms
53,844 KB
testcase_13 AC 37 ms
53,844 KB
testcase_14 AC 38 ms
53,844 KB
testcase_15 AC 37 ms
53,588 KB
testcase_16 AC 37 ms
53,844 KB
testcase_17 AC 37 ms
53,844 KB
testcase_18 AC 37 ms
53,844 KB
testcase_19 AC 37 ms
53,844 KB
testcase_20 AC 38 ms
53,844 KB
testcase_21 AC 37 ms
53,844 KB
testcase_22 AC 36 ms
53,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd


def MillerRabin(n):
    if n <= 1:
        return False
    elif n == 2:
        return True
    elif n % 2 == 0:
        return False

    if n < 4759123141:
        A = [2, 7, 61]
    else:
        A = [2, 325, 9375, 28178, 450775, 9780504, 1795265022]
    s = 0
    d = n - 1
    while d % 2 == 0:
        s += 1
        d >>= 1

    for a in A:
        if a % n == 0:
            return True
        x = pow(a, d, n)
        if x != 1:
            for t in range(s):
                if x == n - 1:
                    break
                x = x * x % n
            else:
                return False
    return True


def pollard(n):
    # https://qiita.com/t_fuki/items/7cd50de54d3c5d063b4a

    if n % 2 == 0:
        return 2

    m = int(n**0.125) + 1
    step = 0

    while 1:
        step += 1

        def f(x):
            return (x * x + step) % n

        y = k = 0
        g = q = r = 1

        while g == 1:
            x = y
            while k < 3 * r // 4:
                y = f(y)
                k += 1
            while k < r and g == 1:
                ys = y
                for _ in range(min(m, r - k)):
                    y = f(y)
                    q = q * abs(x - y) % n
                g = gcd(q, n)
                k += m
            k = r
            r <<= 1

        if g == n:
            g = 1
            y = ys
            while g == 1:
                y = f(y)
                g = gcd(abs(x - y), n)

        if g == n:
            continue
        if MillerRabin(g):
            return g
        elif MillerRabin(n // g):
            return n // g
        else:
            return pollard(g)


def primefact(n):
    res = []
    while n > 1 and not MillerRabin(n):
        p = pollard(n)
        while n % p == 0:
            res.append(p)
            n //= p
    if n != 1:
        res.append(n)
    return sorted(res)


def primedict(n):
    P = primefact(n)
    ret = {}
    for p in P:
        ret[p] = ret.get(p, 0) + 1
    return ret


MOD = 998244353

n, m = map(int, input().split())
ps = primedict(m)
ans = 1
for v in ps.values():
    ans *= pow(v + 1, n, MOD) - pow(v, n, MOD)
    ans %= MOD

print(ans)
0