#include <bits/stdc++.h>
using namespace std;
vector<int>glob;
long long wynmn(long long x){
long long pom;
while(x>=10){
pom=1;
while(x>0){
pom*=(x%10);
x/=10;
}
x=pom;
}
return x;
}
struct dps{
int p,t,s;
long long pr;
bool operator==(const dps &oth)const{
if (p!=oth.p)return false;
if (t!=oth.t)return false;
if (s!=oth.s)return false;
if (pr!=oth.pr)return false;
return true;
}
};
struct dpsh{
size_t operator()(const dps &x)const{
size_t war=13;
war=war*31+x.p*37;
war=war*31+x.s*137;
war=war*31+x.t*2137;
war=war*31+(x.pr^(x.pr>>3))*2654435761ULL;
return war;
}
};
unordered_map<dps,array<long long,10>,dpsh>dpw;
struct fs{
int r,s;
long long pr;
bool operator==(const fs &oth)const{
if (r!=oth.r)return false;
if (s!=oth.s)return false;
if (pr!=oth.pr)return false;
return true;
}
};
struct fsh{
size_t operator()(const fs &x)const{
size_t war=13;
war=war*31+x.r*37;
war=war*31+x.s*137;
war=war*31+(x.pr^(x.pr>>3))*2654435761ULL;
return war;
}
};
unordered_map<fs,array<long long,10>,fsh>frm;
array<long long,10>dpf(int r,int s,long long pr){
array<long long,10>wyn={0,0,0,0,0,0,0,0,0,0};
if(r==0){
if(s)wyn[wynmn(pr)]=1;
return wyn;
}
fs pom {r,s,pr};
if(frm.count(pom))return frm[pom];
int cyfr,ns; long long npr;
if(s)cyfr=1;
else cyfr=0;
for(int i=cyfr;i<10;i++){
if(s&&i==0)continue;
ns=s; npr=pr;
if(!s){
if(i==0){
ns=0;
npr=1;
}
else{
ns=1;
npr=i;
}
}
else npr=pr*i;
auto pom2=dpf(r-1,ns,npr);
for(int j=0;j<10;j++)wyn[j]+=pom2[j];
}
frm[pom]=wyn;
return wyn;
}
array<long long,10>dp(int p,int t,int s,long long pr){
int x=glob.size();
array<long long,10>wyn={0,0,0,0,0,0,0,0,0,0};
if(p==x){
if(s)wyn[wynmn(pr)]=1;
return wyn;
}
dps pom={p,t,s,pr};
if(t==0)return dpf(x-p,s,pr);
if(dpw.count(pom))return dpw[pom];
int lim=glob[p],nt,ns; long long npr;
for(int i=0;i<=lim;i++){
if(i==lim)nt=1;
else nt=0;
ns=s;
if(!s){
if(i==0){
ns=0;
npr=1;
}
else{
ns=1;
npr=i;
}
}
else{
if(i==0)continue;
npr=pr*i;
}
auto pom2=dp(p+1,nt,ns,npr);
for(int j=0;j<10;j++)wyn[j]+=pom2[j];
}
dpw[pom]=wyn;
return wyn;
}
long long dpcnz(int p,int t,int s,const vector<int>&cyf,vector<vector<vector<long long>>>& wync){
int x=glob.size();
if(p==x){
if(s)return 1LL;
else return 0LL;
}
if(wync[p][t][s]!=-1)return wync[p][t][s];
long long pom1=0;
int lim;
if(t)lim=cyf[p];
else lim=9;
int nt,ns;
for(int i=0;i<=lim;i++){
if(t&&i==lim)nt=1;
else nt=0;
ns=s;
if(!s){
if(i==0)ns=0;
else ns=1;
}
else if(i==0)continue;
pom1+=dpcnz(p+1,nt,ns,cyf,wync);
}
wync[p][t][s]=pom1;
return pom1;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t;cin>>t;
vector<long long>pyt(t);
for(int i=0;i<t;i++)cin>>pyt[i];
long long n; string s;
for(int i=0;i<t;i++){
n=pyt[i]; s=to_string(n);
glob.clear();
for(char c:s)glob.push_back(c-'0');
dpw.clear();
array<long long,10>dnz=dp(0,1,0,1);
long long cnt=0;
for(int j=0;j<10;j++)cnt+=dnz[j];
int x=glob.size();
vector<vector<vector<long long>>>wync(x,vector<vector<long long>>(2,vector<long long>(2,-1)));
long long cn=dpcnz(0,1,0,glob,wync);
long long cwz=n-cn;
array<long long,10>wynik;
for(int j=0;j<10;j++)wynik[j]=dnz[j];
wynik[0]+=cwz;
for(int j=0;j<10;j++)cout<<wynik[j]<<" ";
cout<<"\n";
}
return 0;
}
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 184 185 186 187 188 189 190 | #include <bits/stdc++.h> using namespace std; vector<int>glob; long long wynmn(long long x){ long long pom; while(x>=10){ pom=1; while(x>0){ pom*=(x%10); x/=10; } x=pom; } return x; } struct dps{ int p,t,s; long long pr; bool operator==(const dps &oth)const{ if (p!=oth.p)return false; if (t!=oth.t)return false; if (s!=oth.s)return false; if (pr!=oth.pr)return false; return true; } }; struct dpsh{ size_t operator()(const dps &x)const{ size_t war=13; war=war*31+x.p*37; war=war*31+x.s*137; war=war*31+x.t*2137; war=war*31+(x.pr^(x.pr>>3))*2654435761ULL; return war; } }; unordered_map<dps,array<long long,10>,dpsh>dpw; struct fs{ int r,s; long long pr; bool operator==(const fs &oth)const{ if (r!=oth.r)return false; if (s!=oth.s)return false; if (pr!=oth.pr)return false; return true; } }; struct fsh{ size_t operator()(const fs &x)const{ size_t war=13; war=war*31+x.r*37; war=war*31+x.s*137; war=war*31+(x.pr^(x.pr>>3))*2654435761ULL; return war; } }; unordered_map<fs,array<long long,10>,fsh>frm; array<long long,10>dpf(int r,int s,long long pr){ array<long long,10>wyn={0,0,0,0,0,0,0,0,0,0}; if(r==0){ if(s)wyn[wynmn(pr)]=1; return wyn; } fs pom {r,s,pr}; if(frm.count(pom))return frm[pom]; int cyfr,ns; long long npr; if(s)cyfr=1; else cyfr=0; for(int i=cyfr;i<10;i++){ if(s&&i==0)continue; ns=s; npr=pr; if(!s){ if(i==0){ ns=0; npr=1; } else{ ns=1; npr=i; } } else npr=pr*i; auto pom2=dpf(r-1,ns,npr); for(int j=0;j<10;j++)wyn[j]+=pom2[j]; } frm[pom]=wyn; return wyn; } array<long long,10>dp(int p,int t,int s,long long pr){ int x=glob.size(); array<long long,10>wyn={0,0,0,0,0,0,0,0,0,0}; if(p==x){ if(s)wyn[wynmn(pr)]=1; return wyn; } dps pom={p,t,s,pr}; if(t==0)return dpf(x-p,s,pr); if(dpw.count(pom))return dpw[pom]; int lim=glob[p],nt,ns; long long npr; for(int i=0;i<=lim;i++){ if(i==lim)nt=1; else nt=0; ns=s; if(!s){ if(i==0){ ns=0; npr=1; } else{ ns=1; npr=i; } } else{ if(i==0)continue; npr=pr*i; } auto pom2=dp(p+1,nt,ns,npr); for(int j=0;j<10;j++)wyn[j]+=pom2[j]; } dpw[pom]=wyn; return wyn; } long long dpcnz(int p,int t,int s,const vector<int>&cyf,vector<vector<vector<long long>>>& wync){ int x=glob.size(); if(p==x){ if(s)return 1LL; else return 0LL; } if(wync[p][t][s]!=-1)return wync[p][t][s]; long long pom1=0; int lim; if(t)lim=cyf[p]; else lim=9; int nt,ns; for(int i=0;i<=lim;i++){ if(t&&i==lim)nt=1; else nt=0; ns=s; if(!s){ if(i==0)ns=0; else ns=1; } else if(i==0)continue; pom1+=dpcnz(p+1,nt,ns,cyf,wync); } wync[p][t][s]=pom1; return pom1; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t;cin>>t; vector<long long>pyt(t); for(int i=0;i<t;i++)cin>>pyt[i]; long long n; string s; for(int i=0;i<t;i++){ n=pyt[i]; s=to_string(n); glob.clear(); for(char c:s)glob.push_back(c-'0'); dpw.clear(); array<long long,10>dnz=dp(0,1,0,1); long long cnt=0; for(int j=0;j<10;j++)cnt+=dnz[j]; int x=glob.size(); vector<vector<vector<long long>>>wync(x,vector<vector<long long>>(2,vector<long long>(2,-1))); long long cn=dpcnz(0,1,0,glob,wync); long long cwz=n-cn; array<long long,10>wynik; for(int j=0;j<10;j++)wynik[j]=dnz[j]; wynik[0]+=cwz; for(int j=0;j<10;j++)cout<<wynik[j]<<" "; cout<<"\n"; } return 0; } |
English