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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <cstdlib>
#include <bitset>
#include <functional>
#include <utility>
#include <chrono>
#include <tuple>
#include <new>
#include <memory>
#include <climits>
#include <cfloat>
#include <cinttypes>
#include <exception>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <forward_list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>
#include <valarray>
#include <ios>
#include <istream>
#include <ostream>
#include <iostream>
#include <fstream>
#include <streambuf>
#include <cstdio>
#include <thread>
// #include <bits/stdc++.h>
using namespace std;

int q;
vector<long long> pytania;
long long n;
long long prefiksowe[11][10000005], wyn[10000005];
long long maksymalny = 0, tymcz, reszta;
long long iloczyn_cyfr(long long x)
{
    long long odp = 1;
    while (x > 0)
    {
        reszta = x % 10;
        odp *= reszta;
        x /= 10;
    }

    return odp;
}
int main()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> q;
    for (int i = 1; i <= q; i++)
    {
        cin >> n;
        pytania.push_back(n);
        maksymalny = max(maksymalny, n);
    }
    for (long long i = 0; i <= 9; i++)
        wyn[i] = i;

    for (long long akt = 1; akt <= maksymalny; akt++)
    {
        for (int i = 0; i <= 9; i++)
            prefiksowe[i][akt] = prefiksowe[i][akt - 1];

        tymcz = iloczyn_cyfr(akt);
        wyn[akt] = wyn[tymcz];

        prefiksowe[wyn[akt]][akt]++;
    }

    for (auto x : pytania)
    {
        for (int i = 0; i <= 9; i++)
        {
            cout << prefiksowe[i][x] << " ";
        }
        cout << "\n";
    }
}