結果

問題 No.2699 Simple Math (Returned)
ユーザー highlighterhighlighter
提出日時 2024-03-29 21:09:54
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 826 bytes
コンパイル時間 2,919 ms
コンパイル使用メモリ 247,576 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-03-29 21:10:14
合計ジャッジ時間 12,360 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 614 ms
6,548 KB
testcase_02 AC 740 ms
6,548 KB
testcase_03 AC 614 ms
6,548 KB
testcase_04 WA -
testcase_05 AC 722 ms
6,548 KB
testcase_06 AC 679 ms
6,548 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long

int power(int a,int b,int mod){
	vector<int> vec(62);
	vec[0]=a%mod;
	for(int i=1;i<62;i++){
		vec[i]=vec[i-1]*vec[i-1]%mod;
	}
	bitset<62> x(b);
	int ans=1;
	for(int i=0;i<62;i++){
		if(x[i]==1){
			ans*=vec[i];
			ans%=mod;
		}
	}
	return ans;
}

const int mod=998244353;

signed main(){
	int T;
	cin >> T;
	for(;T--;){
		int N,M;
		cin >> N >> M;
		if(N<=M){
			int ans=power(10,N,mod)-1;
			ans%=mod;
			if(ans<0){
				ans+=mod;
			}
			cout << ans << endl;
			continue;
		}
		int t=N%(2*M);
		if(t<=M){
			int ans=power(10,t,mod)-1;
			ans%=mod;
			if(ans<0){
				ans+=mod;
			}
			cout << ans << endl;
			continue;
		}
		if(t>M){
			int ans=power(10,t-M,mod)+1;
			ans*=-1;
			ans%=mod;
			if(ans<0){
				ans+=mod;
			}
			cout << ans << endl;
		}
	}
}
0