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
#include<bits/stdc++.h>
using namespace std;

const int MAXN = 30*1000*1000 + 27863;

int wyn[MAXN][10];

int dziel(int x) {
    if (x < 10) {
        return x;
    }
    int iloczyn = 1;
    while (x > 0) {
        iloczyn *= (x % 10);
        x /= 10;
    }
    return dziel(iloczyn);
}

int main () {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    for (int i = 1; i < MAXN; i ++) {
        for (int j = 0; j < 10; j ++) {
            wyn[i][j] += wyn[i - 1][j];
        }
        wyn[i][dziel(i)] ++;
    }

    int t, n;
    cin >> t;
    for (int i = 0; i < t; i ++) {
        cin >> n;
        for (int j = 0; j < 10; j ++) {
            cout << wyn[n][j] << " ";
        }
        cout << "\n";
    }

    return 0;
}