結果

問題 No.2576 LCM Pattern
ユーザー 👑 H20H20
提出日時 2023-11-20 01:10:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 1,083 bytes
コンパイル時間 178 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 66,640 KB
最終ジャッジ日時 2023-12-03 23:30:07
合計ジャッジ時間 2,058 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
55,604 KB
testcase_01 AC 43 ms
55,604 KB
testcase_02 AC 42 ms
55,604 KB
testcase_03 AC 42 ms
55,604 KB
testcase_04 AC 42 ms
55,604 KB
testcase_05 AC 42 ms
55,604 KB
testcase_06 AC 46 ms
55,604 KB
testcase_07 AC 45 ms
59,316 KB
testcase_08 AC 41 ms
55,604 KB
testcase_09 AC 42 ms
55,604 KB
testcase_10 AC 41 ms
55,604 KB
testcase_11 AC 41 ms
55,604 KB
testcase_12 AC 42 ms
55,604 KB
testcase_13 AC 62 ms
66,640 KB
testcase_14 AC 60 ms
66,636 KB
testcase_15 AC 44 ms
59,316 KB
testcase_16 AC 41 ms
55,604 KB
testcase_17 AC 41 ms
55,604 KB
testcase_18 AC 40 ms
55,604 KB
testcase_19 AC 42 ms
55,604 KB
testcase_20 AC 41 ms
55,604 KB
testcase_21 AC 41 ms
55,604 KB
testcase_22 AC 41 ms
55,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections
#素因数分解
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

N,M = map(int, input().split())
CP = collections.Counter(prime_factorize(M))
mod = 998244353
ans = 0
V = list(CP.values())#各素因数の指数を算出
X = len(CP)
for bit in range(1 << X):
    #以下の列の種類数を算出
    #bitが立っている場合は、1とその素因数の最大の指数-1まで使用可能
    #bitが立っていない場合は、1とその素因数の最大の指数まで使用可能
    st = 1
    for i in range(X):
        if bit >> i & 1:
            st = st*pow(V[i],N,mod)%mod
        else:
            st = st*pow(V[i]+1,N,mod)%mod
    #包除原理
    pcnt = bin(bit).count('1') 
    ans += st * (1 if pcnt % 2 == 0 else -1)#bitの立っている個数が偶数なら足して、奇数なら引く
    ans %= mod
print(ans)
0