結果

問題 No.2896 Monotonic Prime Factors
ユーザー N-noa21
提出日時 2024-09-21 00:28:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 829 ms / 2,000 ms
コード長 867 bytes
コンパイル時間 397 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 251,776 KB
最終ジャッジ日時 2024-09-21 00:29:08
合計ジャッジ時間 15,067 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

Q = int(input())

sieve = [i for i in range(10**5+1)]
p = 2
while p*p <= 10**5:
    if sieve[p] == p:
        for q in range(2*p,10**5+1,p):
            if sieve[q] == q:
                sieve[q] = p
    p += 1
from collections import defaultdict

def cmb(n, r, p):#nCr mod p
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 998244353
binomial_max = int(1.6 * 10 ** 6 + 1)  # N は必要分だけ用意する
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]

for i in range(2, binomial_max + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

cnt = 0
for i in range(Q):
    A,B = map(int, input().split())

    tmp = A
    while tmp>1:
        cnt += 1
        tmp //= sieve[tmp]
    print(cmb(cnt-1,B-1,p))

    


0