题目描述
给出 n , k n,\ k n, k,求数字 k ( 1 < = 9 ) k(1\ <=\ 9) k(1 <= 9)复制n遍在对998244353取模
思路
k
k
k
k
k
k
k
k
⋅
⋅
⋅
\ \ \ \ \ kkkkkkkk···%mod
kkkkkkkk⋅⋅⋅
=
k
∗
1111111
⋅
⋅
⋅
=\ k\ *\ 1111111···
= k ∗ 1111111⋅⋅⋅
=
k
∗
(
9999999
⋅
⋅
⋅
/
9
)
=\ k\ *\ (9999999···\ /\ 9)
= k ∗ (9999999⋅⋅⋅ / 9)
=
k
∗
(
(
10000000
⋅
⋅
⋅
−
1
)
/
9
)
=\ k\ *\ ((10000000··· - 1)\ /\ 9)
= k ∗ ((10000000⋅⋅⋅−1) / 9)
这里除以9需要用逆元
代码
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#define ll long long
using namespace std;
const ll mo = 998244353;
ll n, m, k, T;
ll power(ll a, ll b)
{
a %= mo;
ll ans = 1;
while(b)
{
if(b & 1)ans = ans * a % mo;
a = a * a % mo;
b >>= 1;
}
return ans;
}
int main()
{
scanf("%lld", &T);
m = power(9, mo - 2);
while(T--)
{
scanf("%lld%lld", &n, &k);
printf("%lld\n", (((power(10, n) - 1) * m) % mo * k) % mo);
}
return 0;
}