結果

問題 No.2896 Monotonic Prime Factors
ユーザー t98slider
提出日時 2024-09-21 19:24:20
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 903 bytes
コンパイル時間 3,923 ms
コンパイル使用メモリ 252,124 KB
最終ジャッジ日時 2025-02-24 11:24:06
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using mint = atcoder::modint998244353;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    constexpr int r = 100'000, r2 = 1600'000;
    int idx = 0, tot = 0;
    vector<int> tb(r + 1, 1), cnt(r + 1);
    for(int i = 2; i <= r; i++){
        if (tb[i] == i) continue;
        const int coef = i / tb[i];
        for(int j = i; j <= r; j += i){
            tb[j] *= coef;
            cnt[j]++;
        }
    }
    vector<mint> fact(r2 + 1), inv(r2 + 1);
    fact[0] = 1;
    for(int i = 1; i <= r2; i++) fact[i] = i * fact[i - 1];
    inv[r2] = 1 / fact[r2];
    for(int i = r2; i >= 1; i--) inv[i - 1] = i * inv[i];
    int q;
    cin >> q;
    while(q--){
        int a, b;
        cin >> a >> b;
        tot += cnt[a];
        cout << (tot >= b ? (fact[tot - 1] * inv[tot - b] * inv[b - 1]).val() : 0) << '\n';
    }
}
0