結果

問題 No.2818 A Game I Play to Pass the Time
ユーザー kotatsugame
提出日時 2024-07-20 00:01:21
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 500 ms / 2,000 ms
コード長 706 bytes
コンパイル時間 712 ms
コンパイル使用メモリ 67,584 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-20 00:01:38
合計ジャッジ時間 13,477 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cassert>
#include<atcoder/modint>
using namespace std;
using mint=atcoder::modint998244353;
mint inv[101];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	for(int i=1;i<=100;i++)inv[i]=mint::raw(i).inv();
	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=inv[p];
			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*=inv[e-f+1];
				pp*=invp;
			}
			ans*=now;
		}
		cout<<ans.val()<<"\n";
	}
}
0