結果

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

テストケース

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

ソースコード

diff #

class mod_int:
    """有限体上の整数

    有限体上の整数とその演算を扱うクラスです.

    Attributes:
        value (int): 整数の値.
        mod (int): 有限体の法.
    """
    def __init__(self, value, mod):
        self.value = value % mod
        self.mod = mod

    def __neg__(self):
        return mod_int(-self.value, self.mod)

    def __add__(self, other):
        if type(other) is mod_int:
            return mod_int(self.value + other.value, self.mod)
        elif type(other) is int:
            return mod_int(self.value + other, self.mod)
        raise TypeError()

    def __sub__(self, other):
        return self + (-other)

    def __mul__(self, other):
        if type(other) is mod_int:
            return mod_int(self.value * other.value, self.mod)
        elif type(other) is int:
            return mod_int(self.value * other, self.mod)
        raise TypeError()

    def __truediv__(self, other):
        if type(other) in [mod_int, int]:
            return self * other ** (self.mod - 2)
        raise TypeError()

    def __pow__(self, other):
        if type(other) is not int:
            raise TypeError()
        cur, ret = self.value, 1
        while other > 0:
            if other % 2:
                ret = (ret * cur) % self.mod
            other //= 2
            cur = (cur ** 2) % self.mod
        return mod_int(ret, self.mod)

    def __repr__(self):
        return str(self.value)


def factorize(a):
    """素因数分解

    素因数分解します. O(√a)で動作します.

    Args:
        a (int): 素因数分解したい正整数.

    Returns:
        list[int]: 素因数分解の結果. 例えばa=12なら[2, 2, 3]を返します.
    """
    i = 2
    ans = []
    while i ** 2 <= a:
        while a % i == 0:
            ans.append(i)
            a //= i
        i += 1
    if a > 1:
        ans.append(a)
    return ans


N, M = map(int, input().split())
mod = 998244353
ans = mod_int(1, mod)
d = {}
for i in factorize(M):
    d[i] = d.get(i, 0) + 1
for v in d:
    ans *= mod_int(d[v] + 1, mod) ** N - mod_int(d[v], mod) ** N
print(ans)
0