#include <bits/stdc++.h> using namespace std; #define rng(i,a,b) for(int i=int(a);i<=int(b);i++) #define rep(i,b) rng(i,0,b-1) #define gnr(i,b,a) for(int i=int(b);i>=int(a);i--) #define per(i,b) gnr(i,b-1,0) #define pb push_back #define eb emplace_back #define fi first #define se second #define bg begin() #define ed end() #define all(x) x.bg,x.ed #define si(x) int(x.size()) template<class t> using vc=vector<t>; template<class t> using vvc=vc<vc<t>>; typedef long long ll; using pii=pair<int,int>; using vi=vc<int>; using uint=unsigned; using ull=unsigned long long; using pil=pair<int,ll>; using pli=pair<ll,int>; using pll=pair<ll,ll>; using t3=tuple<int,int,int>; ll rand_int(ll l, ll r) { //[l, r] #ifdef LOCAL static mt19937_64 gen; #else static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count()); #endif return uniform_int_distribution<ll>(l, r)(gen); } template <uint MD> struct ModInt { using M = ModInt; const static M G; uint v; ModInt(ll _v = 0) { set_v(_v % MD + MD); } M& set_v(uint _v) { v = (_v < MD) ? _v : _v - MD; return *this; } explicit operator bool() const { return v != 0; } M operator-() const { return M() - *this; } M operator+(const M& r) const { return M().set_v(v + r.v); } M operator-(const M& r) const { return M().set_v(v + MD - r.v); } M operator*(const M& r) const { return M().set_v(ull(v) * r.v % MD); } M operator/(const M& r) const { return *this * r.inv(); } M& operator+=(const M& r) { return *this = *this + r; } M& operator-=(const M& r) { return *this = *this - r; } M& operator*=(const M& r) { return *this = *this * r; } M& operator/=(const M& r) { return *this = *this / r; } bool operator==(const M& r) const { return v == r.v; } M pow(ll n) const { M x = *this, r = 1; while (n) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; } M inv() const { return pow(MD - 2); } friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; } }; using Mint = ModInt<998244353>; using t4 = tuple<int,int,int,int>; using t5 = tuple<int,int,int,int,int>; #define N_ 201000 ll F[19], po[19]; map<ll,int>Map[19]; vc<pll>Z[19]; int C[10], n; int f(ll a){ if(!a)return 0; ll t=1; while(a){ t*=a%10; if(!t)return 0; a/=10; } if(t<10)return t; return f(t); } void Go(int pv, int rem, ll cur, ll c){ if(pv==10){ if(!rem){ Map[n][cur]+=c; } return; } rng(i,0,rem){ C[pv]=i; Go(pv+1, rem-i, cur, c/F[i]); cur=cur*pv; } C[pv]=0; } void init(){ F[0]=1; Map[0][1]=1; ll z = 1; po[0]=1; rng(i,1,18){ F[i]=F[i-1]*i; n=i; Go(1,i,1,F[i]); z*=10; po[i]=z; ll o=z; for(auto &[t,c]: Map[i]){ if(t)o-=c; } Map[n][0]=o; } rng(i,0,18){ for(auto &[t,c]: Map[i]){ Z[i].pb({t,c}); //if(i<=3)printf("%d %lld %d\n",i,t,c); } } } void Solve(){ ll n; scanf("%lld",&n); vc<ll> ans(10); if(n==(ll)1e18){ n--; ans[0]++; } vi w; while(n){ w.pb(n%10); n/=10; } int L = si(w); rng(i,1,L-1){ rng(j,1,9){ for(auto &[t,c] : Z[i-1]){ //printf("%lld %lld\n",t*j,c); ans[f(t*j)] += c; } } } ll cur=1; //rep(i,10)printf("%lld ",ans[i]); per(i,L){ rep(j,w[i]){ if(i==L-1 && j==0)continue; for(auto &[t,c] : Z[i]){ //printf("%lld %d %lld\n",cur*j*t,f(cur*j*t),c); ans[f(cur*j*t)]+=c; } } cur *= w[i]; } ans[f(cur)]++; rep(i,10)printf("%lld ",ans[i]); puts(""); } int main(){ int TC=1; init(); scanf("%d",&TC); while(TC--){ Solve(); } }
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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | #include <bits/stdc++.h> using namespace std; #define rng(i,a,b) for(int i=int(a);i<=int(b);i++) #define rep(i,b) rng(i,0,b-1) #define gnr(i,b,a) for(int i=int(b);i>=int(a);i--) #define per(i,b) gnr(i,b-1,0) #define pb push_back #define eb emplace_back #define fi first #define se second #define bg begin() #define ed end() #define all(x) x.bg,x.ed #define si(x) int(x.size()) template<class t> using vc=vector<t>; template<class t> using vvc=vc<vc<t>>; typedef long long ll; using pii=pair<int,int>; using vi=vc<int>; using uint=unsigned; using ull=unsigned long long; using pil=pair<int,ll>; using pli=pair<ll,int>; using pll=pair<ll,ll>; using t3=tuple<int,int,int>; ll rand_int(ll l, ll r) { //[l, r] #ifdef LOCAL static mt19937_64 gen; #else static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count()); #endif return uniform_int_distribution<ll>(l, r)(gen); } template <uint MD> struct ModInt { using M = ModInt; const static M G; uint v; ModInt(ll _v = 0) { set_v(_v % MD + MD); } M& set_v(uint _v) { v = (_v < MD) ? _v : _v - MD; return *this; } explicit operator bool() const { return v != 0; } M operator-() const { return M() - *this; } M operator+(const M& r) const { return M().set_v(v + r.v); } M operator-(const M& r) const { return M().set_v(v + MD - r.v); } M operator*(const M& r) const { return M().set_v(ull(v) * r.v % MD); } M operator/(const M& r) const { return *this * r.inv(); } M& operator+=(const M& r) { return *this = *this + r; } M& operator-=(const M& r) { return *this = *this - r; } M& operator*=(const M& r) { return *this = *this * r; } M& operator/=(const M& r) { return *this = *this / r; } bool operator==(const M& r) const { return v == r.v; } M pow(ll n) const { M x = *this, r = 1; while (n) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; } M inv() const { return pow(MD - 2); } friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; } }; using Mint = ModInt<998244353>; using t4 = tuple<int,int,int,int>; using t5 = tuple<int,int,int,int,int>; #define N_ 201000 ll F[19], po[19]; map<ll,int>Map[19]; vc<pll>Z[19]; int C[10], n; int f(ll a){ if(!a)return 0; ll t=1; while(a){ t*=a%10; if(!t)return 0; a/=10; } if(t<10)return t; return f(t); } void Go(int pv, int rem, ll cur, ll c){ if(pv==10){ if(!rem){ Map[n][cur]+=c; } return; } rng(i,0,rem){ C[pv]=i; Go(pv+1, rem-i, cur, c/F[i]); cur=cur*pv; } C[pv]=0; } void init(){ F[0]=1; Map[0][1]=1; ll z = 1; po[0]=1; rng(i,1,18){ F[i]=F[i-1]*i; n=i; Go(1,i,1,F[i]); z*=10; po[i]=z; ll o=z; for(auto &[t,c]: Map[i]){ if(t)o-=c; } Map[n][0]=o; } rng(i,0,18){ for(auto &[t,c]: Map[i]){ Z[i].pb({t,c}); //if(i<=3)printf("%d %lld %d\n",i,t,c); } } } void Solve(){ ll n; scanf("%lld",&n); vc<ll> ans(10); if(n==(ll)1e18){ n--; ans[0]++; } vi w; while(n){ w.pb(n%10); n/=10; } int L = si(w); rng(i,1,L-1){ rng(j,1,9){ for(auto &[t,c] : Z[i-1]){ //printf("%lld %lld\n",t*j,c); ans[f(t*j)] += c; } } } ll cur=1; //rep(i,10)printf("%lld ",ans[i]); per(i,L){ rep(j,w[i]){ if(i==L-1 && j==0)continue; for(auto &[t,c] : Z[i]){ //printf("%lld %d %lld\n",cur*j*t,f(cur*j*t),c); ans[f(cur*j*t)]+=c; } } cur *= w[i]; } ans[f(cur)]++; rep(i,10)printf("%lld ",ans[i]); puts(""); } int main(){ int TC=1; init(); scanf("%d",&TC); while(TC--){ Solve(); } } |