結果

問題 No.2576 LCM Pattern
ユーザー hiro1729hiro1729
提出日時 2023-12-04 07:15:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 1,492 bytes
コンパイル時間 489 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 53,844 KB
最終ジャッジ日時 2023-12-04 07:15:46
合計ジャッジ時間 1,961 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

from math import gcd
def isp(n):
    if n == 2: return True
    if n == 1 or n % 2 == 0: return False
    m = n - 1;l = m & -m;s = l.bit_length() - 1;d = m // l
    for a in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]:
        if a == n: continue
        x = pow(a, d, n);r = 0
        if x == 1: continue
        while x != m:
            x = pow(x, 2, n);r += 1
            if x == 1 or r == s: return False
    return True
def findf(n):
    if n % 2 == 0: return 2
    m = int(n ** 0.125) + 1
    for c in range(1, n):
        def f(y): return (y * y + c) % 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 *= 2
        if g == n:
            g = 1;y = ys
            while g == 1: y = f(y);g = gcd(abs(x - y), n)
        if g == n: continue
        if isp(g): return g
        elif isp(n // g): return n // g
        else: return findf(g)
def factorize(n):
    res = []
    while not isp(n) and n > 1:
        p = findf(n)
        e = 0
        while n % p == 0:n //= p;e += 1
        res.append((p, e))
    if n > 1: res.append((n, 1))
    res.sort()
    return res

n, m = map(int, input().split())
ans = 1
mod = 998244353
for p, e in factorize(m):
	ans *= pow(e + 1, n, mod) - pow(e, n, mod)
	ans %= mod
print(ans)
0