Educational Codeforces Round 84 E. Count The Blocks

Portal : 1327- E. Count The Blocks 

Question is intended: to give you an integer n, seeking 10 ^ n (the number of each leading zero) length of 1 to n, the number of blocks, respectively. The blocks are consecutive identical digits length.

Solution: from n = 1 begins the enumeration, ans array record the number of blocks per length. Current ans [n-] is the value of the next ans n ++ [n] value, so that each time only 1 block length is counted how many like. For convenience, ans array reverse record. Blocks of length 1 is in fact the total number of digits minus the length of digits contained 2 ~ n. For example when n = 1, the number 1 has a length of 10, when n = 2, the number 1 is a length of 10 ^ 2 * 2-10 * 2 = 180, n = 3, a length of 1 number is 10 ^ 3 * 3-180 * 2-10 * 3 = 2610;

 1 #include<bits/stdc++.h>
 2 #define ll long long
 3 using namespace std;
 4 
 5 const ll mod=998244353;
 6 ll ans[200100],p[200100];
 7 
 8 ll  quick(ll a,ll b)
 9 {
10     ll res=1;
11     a=a%mod;
12     while(b){
13         if(b&1) res=(res*a)%mod;
14         a=(a*a)%mod;
15         b>>=1;
16     }
17     return res;
18 }
19 
20 int main()
21 {
22     ios::sync_with_stdio(false);
23     cin.tie(0);
24     cout.tie(0);
25     ll n;
26     cin>>n;
27     ans[1]=10;
28     p[1]=10;
29     ll sum=p[1]+ans[1];
30     for(ll i=2;i<=n;i++){
31         ans[i]=quick(10,i)*i%mod-sum+mod;
32         ans[i]%=mod;
33         p[i]=p[i-1]+ans[i];
34         p[i]%=mod;
35         sum+=p[i]+ans[i];
36         sum%=mod;
37     }
38     for(int i=n;i>=1;i--)
39         cout<<ans[i]<<' ';
40     return 0;
41 }

 

Guess you like

Origin www.cnblogs.com/lilibuxiangtle/p/12556481.html
Recommended