結果

問題 No.2474 Empty Quartz
ユーザー Yerin JungYerin Jung
提出日時 2023-09-23 21:13:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 921 bytes
コンパイル時間 2,391 ms
コンパイル使用メモリ 164,884 KB
実行使用メモリ 5,088 KB
最終ジャッジ日時 2023-09-23 21:13:31
合計ジャッジ時間 3,295 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,940 KB
testcase_01 AC 3 ms
4,972 KB
testcase_02 AC 23 ms
4,916 KB
testcase_03 AC 33 ms
4,900 KB
testcase_04 AC 36 ms
4,920 KB
testcase_05 AC 44 ms
5,088 KB
testcase_06 AC 41 ms
5,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
const ll mod=998244353;
const int iu=1e5;
ll n,m;
ll f[iu+1],inf[iu+1];
ll pw(ll x,ll y){
	if(y==0) return 1;
	if(y%2) return x*pw(x,y-1)%mod;
	ll res=pw(x,y/2);
	return res*res%mod;
}
ll C(ll x,ll y){
	if(y>x) return 0;
	return f[x]*inf[y]%mod*inf[x-y]%mod;
}
ll solve(){
	ll ans=0;
	ll l=0,r=(n+1)/2;
	while(l!=r){
		ll mid=(l+r)/2;
		if(mid*(n-mid+1)>=m) r=mid;
		else l=mid+1;
	}
	if(l*(n-l+1)!=m) return 0;
	{
		int k=l;
		
			ans=(ans+C(n,k))%mod;
	}
	{
		int k=n-l+1;
		if(k==n+1 || k==l) return ans;
		
			ans=(ans+C(n,k))%mod;
		
	}
	
	return ans;
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);
	f[0]=1;
	for(int i=1; i<=iu ;i++) f[i]=f[i-1]*i%mod;
	inf[iu]=pw(f[iu],mod-2);
	for(int i=iu; i>=1 ;i--) inf[i-1]=inf[i]*i%mod;
	int t;cin >> t;
	while(t--){
		cin >> n >> m;
		cout << solve() << '\n';
	}
}
0