結果
問題 |
No.2818 A Game I Play to Pass the Time
|
ユーザー |
|
提出日時 | 2024-07-20 00:00:31 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,797 ms / 2,000 ms |
コード長 | 753 bytes |
コンパイル時間 | 648 ms |
コンパイル使用メモリ | 67,968 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-20 00:01:09 |
合計ジャッジ時間 | 38,066 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 19 |
ソースコード
#include<iostream> #include<cassert> #include<atcoder/modint> using namespace std; using mint=atcoder::modint998244353; mint H(long a,int b) { //H(a,b)=C(a+b-1,b) mint x=1,y=1; for(int i=1;i<=b;i++)x*=a+b-i,y*=i; return x/y; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T;cin>>T; for(;T--;) { long N,S; cin>>N>>S; mint ans=S; for(int p=2;p<=100;p++)if(N%p==0) { int e=0; while(N%p==0)N/=p,e++; const mint invp=mint(p).inv(); mint now=0,pp=mint(p).pow(e); for(int f=e;f>=0;f--) { //pp=p.pow(e)*H(S-1,e-f) //=p.pow(e)*C(S-2+e-f,e-f) //=p.pow(e)*(S-2+e-f)...(S-2+1)/(e-f)! now+=pp; pp*=S-2+e-f+1; pp/=e-f+1; pp*=invp; } ans*=now; } cout<<ans.val()<<"\n"; } }