結果

問題 No.2132 1 or X Game
ユーザー rin204
提出日時 2022-11-25 22:12:46
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 725 bytes
コンパイル時間 1,902 ms
コンパイル使用メモリ 192,708 KB
最終ジャッジ日時 2025-02-09 00:20:26
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other WA * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;

long long modpow(long long a, long long b){
	long long ret = 1;
	a %= MOD;
	while(b){
		if(b & 1){
			ret *= a;
			ret %= MOD;
		}
		a *= a;
		a %= MOD;
		b >>= 1;
	}
	return ret;
}

void solve(){
	long long n, x, ans;
	cin >> n >> x;
	if(x & 1){
		ans = (n + 1) / 2;
	}
	else{
		long long  c = n / (2 * x + 2);
		n %= (2 * x + 2);
		/*
		0: lose
		1 ~ x : odd
		x + 1 ~ 2x: even
		2x + 1: win 
		*/
		ans = (x + 1) * c;
		if(n <= x){
			ans += (n + 1) / 2;
		}
		else{
			ans += (x + 1) / 2;
			n -= x;
			ans += n / 2;
			if(n == x + 1) ans++;

		}
	}
	cout << ans % MOD << "\n";
}

int main(){
	int t;
	t = 1;
	cin >> t;
	while(t--) solve();
}
0