#include <bits/stdc++.h> #define debug(x) std::cerr << "Line: " << __LINE__ << ", " << #x << " = " << x << "\n" using i64 = long long; constexpr int N = 20; i64 f[N], p[N]; i64 ans1[N], ans2[N]; int a[N]; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); i64 l, r; std::cin >> l >> r; p[0] = 1LL; for (int i = 1; i <= 13; i++) { f[i] = f[i - 1] * 10 + p[i - 1];//f[i]表示的是在不考虑前导0 的情况下i位数的每种数码的个数 //根据对称性,每一种数码的个数应该相同 p[i] = p[i - 1] * 10;// p[i] 即 10^i, 表示对第i + 1位的贡献 } auto solve = [] (i64 n, i64 ans[]) { int len = 0; i64 tmp = n; while (n) { a[++len] = n % 10; n /= 10; } for (int i = len; i >= 1; i--) { for (int j = 0; j < 10; j++) { ans[j] += f[i - 1] * a[i];//不贴着上界时随便取值 } for (int j = 0; j < a[i]; j++) { ans[j] += p[i - 1];//贴着上界 0 ~ a[i] - 1(若取成a[i]则可能多算了) } tmp -= p[i - 1] * a[i];// 比如4位数ABCD, 求A的数目时, 因为 ABCD = A000 + BCD ,还需要 ans[A] += BCD+1 ans[a[i]] += tmp + 1;//也就是 ans[A] += (ABCD) - (A * 10^(4-1)) + 1 ans[0] -= p[i - 1];//由于到四位数的前导0有 0000, 0001,..., 0011,0012,...,0101,0102,...,0998,0999 //也就是要减去 10^(i-1)次方的前导0 } }; // ans[l,r] = ans[r] - ans[l - 1] solve(r, ans1); solve(l - 1, ans2); for (int i = 0; i < 10; i++) {//对每一位数计算答案即可 std::cout << ans1[i] - ans2[i] << " \n"[i == 9]; } return 0; }