結果

問題 No.2896 Monotonic Prime Factors
ユーザー nikoro256nikoro256
提出日時 2024-09-20 21:56:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,313 ms / 2,000 ms
コード長 982 bytes
コンパイル時間 270 ms
コンパイル使用メモリ 82,256 KB
実行使用メモリ 246,656 KB
最終ジャッジ日時 2024-09-20 21:56:45
合計ジャッジ時間 19,598 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 498 ms
246,656 KB
testcase_01 AC 489 ms
246,656 KB
testcase_02 AC 516 ms
246,400 KB
testcase_03 AC 487 ms
246,656 KB
testcase_04 AC 1,300 ms
246,528 KB
testcase_05 AC 1,313 ms
246,544 KB
testcase_06 AC 1,243 ms
246,400 KB
testcase_07 AC 1,189 ms
246,656 KB
testcase_08 AC 1,241 ms
246,144 KB
testcase_09 AC 1,289 ms
246,400 KB
testcase_10 AC 927 ms
246,272 KB
testcase_11 AC 613 ms
246,400 KB
testcase_12 AC 581 ms
246,656 KB
testcase_13 AC 919 ms
246,656 KB
testcase_14 AC 999 ms
246,528 KB
testcase_15 AC 537 ms
246,144 KB
testcase_16 AC 720 ms
246,656 KB
testcase_17 AC 610 ms
246,656 KB
testcase_18 AC 1,152 ms
246,400 KB
testcase_19 AC 658 ms
246,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def factorization(n):
    arr = []
    temp = n
    i=2
    while i*i<=n:
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
        i+=1
    if temp!=1:
        arr.append([temp, 1])
    return arr


def cmb(n, r, 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
N = 2*10**6  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用S
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

Q=int(input())
count=0
for _ in range(Q):
    a,b=map(int,input().split())
    for c,d in factorization(a):
        count+=d
    if count<b:
        print(0)
    else:
        print(cmb(count-1,b-1,p))
0