結果

問題 No.2699 Simple Math (Returned)
ユーザー highlighter
提出日時 2024-03-29 21:18:31
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 795 ms / 2,000 ms
コード長 699 bytes
コンパイル時間 2,669 ms
コンパイル使用メモリ 245,952 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-09-30 15:31:43
合計ジャッジ時間 11,354 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 11
権限があれば一括ダウンロードができます

ソースコード

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;
		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,M,mod)-power(10,t-M,mod);
			ans%=mod;
			if(ans<0){
				ans+=mod;
			}
			cout << ans << endl;
		}
	}
}
0