結果

問題 No.2818 A Game I Play to Pass the Time
ユーザー 👑 Nachia
提出日時 2024-07-19 22:53:31
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 459 ms / 2,000 ms
コード長 1,840 bytes
コンパイル時間 1,224 ms
コンパイル使用メモリ 99,384 KB
最終ジャッジ日時 2025-02-23 16:46:49
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifdef NACHIA
#define _GLIBCXX_DEBUG
#else
#define NDEBUG
#endif
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <array>
#include <cmath>
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<int(n); i++)
#define repr(i,n) for(int i=int(n)-1; i>=0; i--)
const i64 INF = 1001001001001001001;
const char* yn(bool x){ return x ? "Yes" : "No"; }
template<typename A> void chmin(A& l, const A& r){ if(r < l) l = r; }
template<typename A> void chmax(A& l, const A& r){ if(l < r) l = r; }
template<typename A> using nega_queue = std::priority_queue<A,std::vector<A>,std::greater<A>>;
template<class R> auto ComparingBy(R f){ return [g=std::move(f)](auto l, auto r) -> bool { return g(l) < g(r); }; }
#include <atcoder/modint>
using Modint = atcoder::static_modint<998244353>;
using namespace std;

void testcase(){
    i64 Z = 64;
    int T; cin >> T;
    i64 primes[] = { 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97 };
    vector<Modint> Inv(Z+1);
    for(int i=1; i<=Z; i++) Inv[i] = Modint(i).inv();
    rep(t,T){
        i64 N, S; cin >> N >> S;
        vector<i64> F(25);
        rep(i,25) while(N % primes[i] == 0){ N /= primes[i]; F[i]++; }
        vector<Modint> comb(Z+1);
        comb[0] = 1;
        for(int i=1; i<=Z; i++) comb[i] = comb[i-1] * (S + i - 2) * Inv[i];
        Modint ans = 1;
        rep(i,25) if(F[i]){
            Modint p = primes[i];
            Modint pp = 1;
            Modint t = 0;
            rep(k,F[i]+1){
                t += pp * comb[F[i]-k];
                pp *= p;
            }
            ans *= t;
        }
        ans *= S;
        cout << ans.val() << '\n';
    }
}

int main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);
    testcase();
    return 0;
}
0