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
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i = a; i < b;++i)
#define pb push_back
#define pi pair<int,int>
#define f first
#define s second
using namespace std;
int odp[1005][10];
int obl(int v){
    while(v >= 10){
        int x = v;
        int a = 1;
        while(x > 0){
            a*=(x % 10);
            x/=10;
        }
        v = a;
    }
    return v;
}
int main(){
    vector<pi> V;
    vector<int> akt(10,0);
    int t;
    cin>>t;
    FOR(i,0,t){
        int x;
        cin>>x;
        V.pb({x,i});
    }
    sort(V.begin(),V.end());
    int nr = 1;
    FOR(i,0,V.size()){
        while(nr <= V[i].f){
            akt[obl(nr)]++;
            ++nr;
        }
        FOR(j,0,10){
            odp[V[i].s][j] = akt[j];
        }
    }
    FOR(i,0,t){
        FOR(j,0,10){
            cout<<odp[i][j] <<" ";
        }
        cout<<"\n";
    }
}