E. Count The Blocks
time limit per test :2 seconds memory limit per test :256 megabytes
input :standard input output :standard output
You wrote down all integers from 0 to , padding them with leading zeroes so their lengths are exactly n. For example, if n=3 then you wrote out 000, 001, ..., 998, 999.
A block in an integer x is a consecutive segment of equal digits that cannot be extended to the left or to the right.
For example, in the integer 00027734000 there are three blocks of length 1, one block of length 2 and two blocks of length 3.
For all integers i from 1 to nn count the number of blocks of length i among the written down integers.
Since these integers may be too large, print them modulo 998244353.
Input
The only line contains one integer n ().
Output
In the only line print n integers. The i-th integer is equal to the number of blocks of length i.
Since these integers may be too large, print them modulo 998244353.
Examples
input
1
output
10
input
2
output
180 10
题目大意
有前导零补齐的n位数中长度为i的块有多少() ?(一个块是指连续的数码相同的一段,比如000,11,2222都是一个块,长度分别为3,2,4,而1234不是一个块,但是1,2,3,4分别是长度为1的一个块)
思路
对于n位数长度为i的情况有三种
1. i == n,共有10种
2. i <= n - 1,块在边界,有个长度为i的块
3.块不在边界,此时需满足i <= n - 2,有个长度为i的块
代码
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;
const int mod = 998244353;
const int N = 2e5 + 10;
ll p[N];
int main()
{
int n;
cin >> n;
p[0] = 1;
for (int i = 1; i <= n; ++ i) p[i] = p[i - 1] * 10 % mod;
for (int i = 1; i < n; ++ i){
ll ans = 2 * 10 * 9 * p[n - i - 1] % mod;
if (i <= n - 2) ans = (ans + 10 * (n - i - 1) * 9 * 9 * p[n - i - 2]) % mod;
printf("%lld ", ans);
}
printf("10\n");
return 0;
}