結果

問題 No.2896 Monotonic Prime Factors
ユーザー poeMoon0416poeMoon0416
提出日時 2024-09-20 23:12:10
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,240 bytes
コンパイル時間 306 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 93,240 KB
最終ジャッジ日時 2024-09-20 23:12:17
合計ジャッジ時間 5,208 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 233 ms
93,116 KB
testcase_01 AC 237 ms
87,744 KB
testcase_02 AC 234 ms
87,868 KB
testcase_03 AC 237 ms
87,740 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
from collections import defaultdict

# エラトステネスの篩 O(NloglogN)
def eratosthenes_sieve(lim):
    primes = set(range(3, lim, 2))
    primes.add(2)
    # iが素数か判定(奇数だけ見ていく)
    for i in range(3, lim, 2):
        if i in primes:
            # 素数iの倍数を削除
            for j in range(i*2, lim, i):
                primes.discard(j)
    return primes

# 試し割り法
def prime_factors(src):
    # cnt: 素因数の数
    cnt = 0
    now = src
    i = 0
    # src = i*j のときjがiより大きいなら既出なので√srcまで確認
    while primes[i]*primes[i] <= src:
        # 割り切れるなら割れるだけ割る
        while now%primes[i] == 0:
            now //= primes[i]
            cnt += 1
        i += 1
    # それ以上分解できない残ったものを素因数に加える
    if now > 1:
        cnt += 1
    return cnt

MOD = 998244353

# print(10**5*math.sqrt(10**5))
primes = sorted(list(eratosthenes_sieve(10**5+1)))
memo = defaultdict(int)
for i in range(2, 10**5+1):
    memo[i] = prime_factors(i)

Q = int(input())
cnt = 0
for _ in range(Q):
    A, B = map(int, input().split())
    cnt += memo[A]
    print(math.comb(cnt-1, B-1)%MOD)
0