AtCoder Beginner Contest 357-D
Problem
For a positive integer $N$, let $V_N$ be the integer formed by concatenating $N$ exactly $N$ times.
More precisely, consider $N$ as a string, concatenate $N$ copies of it, and treat the result as an integer to get $V_N$.
For example, $V3=333$ and $V{10}=10101010101010101010$ .
Find the remainder when $V_N$ is divided by $998244353$.
给一个正整数 $N$ ,令 $V_N$ 为 $N$ 重复 $N$ 次,求 $V_N\bmod 998244353$ 。
比如,$V3=333$,$V{12}=121212121212121212121212$,$V_{12}\bmod998244353=214985338$
Constraints
$1\le N \le 10^{18}$
Solution
注意到$N$非常大,肯定需要对$V_N$进行转化。理想应该能够在$\log n$的复杂度内解决。
我们记$w$为$N$的位数,那么有
可以用快速幂和逆元解决了。
Code
1 |
|
Attention
- 注意多取模
- 获取$w$时,不要使用$log10(N)+1$,在$N$较大的时候会有精度误差!
- 要不咱用
python写一遍也是可以的(