CF1327E Count The Blocks

原题链接

  • 题意:求出在从 (1)(10^n-1) 的范围所有数,有多少连续的 (i) 位相同的段个数。
  • 题解:就计数一下,首先是边缘然后是放中间。
  • 代码:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstring>
using namespace std;
#define ___ long long  
const ___ N = 2e7 + 9;
const ___ mod = 998244353;
const ___ P = 13331;
___ cnt[N];
___ q_mi(___ xx, ___ k) {
    ___ ret = 1;
    ___ x = xx;
    while (k) {
        if (k & 1)(ret *= x)%=mod;
        //cout << k << endl;
        k >>= 1;
        (x *= x)%=mod;
    }
    return ret;
}
void solve() {
    ___ n;cin >> n;
    ___ ans = 0;
    int x = 10000;
    int xxx = 10, ttt = 10;
    while (x--)xxx += ttt;
    for (int i = 1; i <= n; i ++) {
        if (i == n){cout << 10 << endl;break;}
        ans = 9 * 10 * q_mi(10, n-1-i)%mod * 2%mod;
        if (n-2-i >= 0) {
            ans +=  9 * 9 * 10 * (q_mi(10, n-2-i))%mod * (n-i-1)%mod;
            ans %= mod;
        }
        cout << ans << " ";
        
    }
}
signed main() {
    ___ t= 1;//cin >> t;
    //ios::sync_with_stdio(0);
    while (t--) {
        solve();
    }
}
原文地址:https://www.cnblogs.com/Xiao-yan/p/14778282.html