1 条题解

  • 0
    @ 2025-8-3 14:43:19

    O(logn)O(logn) 逆元,等比数列求和

    nn 重复 nn 次,可以表示为:

    $ n \times 10^0 + n \times 10^m + n \times 10^{2m} + ... + n \times 10^{(n - 1)m} $ 其中 mmnn 在十进制下的位数。

    提取 nn ,剩下部分为等比数列求和。

    #include<bits/stdc++.h>
    
    using namespace std;
    
    typedef long long LL;
    typedef pair<LL, LL> PII;
    
    #define x first
    #define y second
    
    const int N = 2e5 + 10, mod = 998244353;
    
    LL n;
    
    int qmi(LL a, LL k)  // 求a^k mod p
    {
        int res = 1;
        while (k)
        {
            if (k & 1) res = (LL)res * a % mod;
            a = (LL)a * a % mod;
            k >>= 1;
        }
        return res;
    }
    
    
    void solve()
    {
        cin >> n;
        LL bit = 0, x = n;
        while(x)
        {
            x /= 10;
            bit ++;
        }
        
        LL q = qmi(10, bit);
        LL ans = n % mod * (qmi(q, n) - 1) % mod * qmi(q - 1, mod - 2) % mod;
        cout << ans << endl;
        
    }
    
    int main()
    {
        int t = 1;
        // cin >> t;
        while(t --)
            solve();
    }
    
    
    • 1

    信息

    ID
    474
    时间
    1000ms
    内存
    256MiB
    难度
    8
    标签
    递交数
    17
    已通过
    5
    上传者