1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

int digit_product(int x) {
    int y = 1;
    while (x > 0) {
        y *= x % 10;
        x /= 10;
    }
    return y;
}

int precomp[1000000];

int fold(int64_t x) {
    while (x >= 10) {
        int64_t l = 1;
        while (x > 0) {
            l *= precomp[x % 1000000];
            if (l == 0) break;
            x /= 1000000;
        }
        x = l;
    }
    return x;
}

int main() {
    for (int i = 0; i < 1000000; i++) precomp[i] = digit_product(i);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        vector<int64_t> d(10);
        int64_t x;
        cin >> x;      
        for (int j = 1; j <= x; j++) {
            int r = fold(j);
            d[r]++;
            if (r == 0) {
                // find the first zero digit
                int k = j;
                int p = -1;
                int q = 1;
                int t = 1;
                while (k >= 10) {
                    if (k % 10 == 0) p = k * t + q;
                    t *= 10;
                    q = q*10+1;
                    k /= 10;
                }
                if (p > 0) {
                    // cout << "jump from " << j << " to " << p << endl;
                    d[0] += (p - j - 1);
                    j = p - 1;
                }
            }
        }
        for (int i = 0; i < 10; i++) {
            cout << d[i] << " ";
        }
        cout << endl;
    }
    return 0;
}