#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
ll brut(ll a)
{
if(a<10)
return a;
ll res=1;
while(a)
{
res*=(a%10);
a/=10;
}
return brut(res);
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin>>t;
vector<vector<ll>>anss(t);
vector<pair<ll, int>>q;
for(int i=0; i<t; i++)
{
ll cur;
cin>>cur;
q.push_back({cur, i});
}
sort(q.begin(), q.end());
reverse(q.begin(), q.end());
vector<ll>pot2(60, 1), pot3(38, 1), pot5(26, 1), pot7(22, 1);
for(int i=1; i<60; i++)
pot2[i]=pot2[i-1]*2;
for(int i=1; i<38; i++)
pot3[i]=pot3[i-1]*3;
for(int i=1; i<26; i++)
pot5[i]=pot5[i-1]*5;
for(int i=1; i<22; i++)
pot7[i]=pot7[i-1]*7;
unordered_map<ll, ll>m;
ll ctr=0;
ll n=q[0].first;
for(int a=0; a<60; a++)
{
for(int b=0; b<=37; b++)
{
for(int c=0; c<=25; c++)
{
for(int d=0; d<=21; d++)
{
ll cur=pot2[a];
if(cur>n/pot3[b])
break;
cur*=pot3[b];
if(cur>n/pot5[c])
break;
cur*=pot5[c];
if(cur>n/pot7[d])
break;
cur*=pot7[d];
m[cur]=brut(cur);
//cout<<cur<<endl;
//res++;
//ctr++;
}
}
}
}
//cout<<ctr<<endl;
m[0]=0;
int lgmax=0;
ll tmp=q[0].first;
while(tmp)
{
lgmax++;
tmp/=10;
}
vector<map<ll, ll>>dpp(lgmax);
for(int i=0; i<10; i++)
dpp[0][i]=1;
for(int i=1; i<lgmax; i++)
{
for(int j=0; j<10; j++)
{
for(auto x:dpp[i-1])
{
if(dpp[i].find(x.first*j)==dpp[i].end())
dpp[i][x.first*j]=0;
dpp[i][x.first*j]+=x.second;
}
}
}
for(int gg=0; gg<t; gg++)
{
//cout<<q[gg].first<<" "<<q[gg].second<<endl;
//cout<<" G\n";
//ll res=0;
n=q[gg].first;
vector<ll>res(10, 0);
if(n<10)
{
for(int i=1; i<=n; i++)
res[i]=1;
}
else
{
vector<int>v;
ll tmp=n;
int lg=0;
while(tmp)
{
lg++;
v.push_back(tmp%10);
tmp/=10;
}
//cout<<lg<<" lg\n";
res.clear();
res.resize(10, 1);
res[0]=0;
for(int k=1; k<lg-1; k++)
{
for(int i=1; i<10; i++)
{
for(auto x:dpp[k-1])
{
res[m[x.first*i]]+=x.second;
}
}
}
for(int i=1; i<v[lg-1]; i++)
{
for(auto x:dpp[lg-2])
{
res[m[x.first*i]]+=x.second;
}
}
vector<map<ll, ll>>dp=dpp;
/*
for(auto y:dp)
{
for(auto x:y)
cout<<x.first<<" "<<x.second<<endl;
}
cout<<" b\n";
*/
for(int k=lg-1; k>0; k--)
{
//cout<<k<<endl;
if(k==1)
{
dp[0].clear();
for(int j=0; j<=v[0]; j++)
dp[0][j]=1;
}
else
{
dp[k-1].clear();
for(int j=0; j<v[k-1]; j++)
{
for(auto x:dp[k-2])
{
if(dp[k-1].find(x.first*j)==dp[k-1].end())
dp[k-1][x.first*j]=0;
dp[k-1][x.first*j]+=x.second;
}
}
}
//cout<<"zyw\n";
for(int i=k; i<lg; i++)
{
dp[i].clear();
for(auto x:dp[i-1])
{
if(dp[i].find(x.first*v[i])==dp[i].end())
dp[i][x.first*v[i]]=0;
dp[i][x.first*v[i]]+=x.second;
}
}
for(auto x:dp[lg-2])
{
//cout<<x.first<<" YO "<<x.second<<endl;
res[m[x.first*v[lg-1]]]+=x.second;
}
}
//res[brut(n)]++;
}
anss[q[gg].second]=res;
}
for(auto x:anss)
{
for(auto y:x)
cout<<y<<" ";
cout<<"\n";
}
}
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 191 192 193 194 195 196 197 198 199 | #include<bits/stdc++.h> using namespace std; typedef unsigned long long ll; ll brut(ll a) { if(a<10) return a; ll res=1; while(a) { res*=(a%10); a/=10; } return brut(res); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin>>t; vector<vector<ll>>anss(t); vector<pair<ll, int>>q; for(int i=0; i<t; i++) { ll cur; cin>>cur; q.push_back({cur, i}); } sort(q.begin(), q.end()); reverse(q.begin(), q.end()); vector<ll>pot2(60, 1), pot3(38, 1), pot5(26, 1), pot7(22, 1); for(int i=1; i<60; i++) pot2[i]=pot2[i-1]*2; for(int i=1; i<38; i++) pot3[i]=pot3[i-1]*3; for(int i=1; i<26; i++) pot5[i]=pot5[i-1]*5; for(int i=1; i<22; i++) pot7[i]=pot7[i-1]*7; unordered_map<ll, ll>m; ll ctr=0; ll n=q[0].first; for(int a=0; a<60; a++) { for(int b=0; b<=37; b++) { for(int c=0; c<=25; c++) { for(int d=0; d<=21; d++) { ll cur=pot2[a]; if(cur>n/pot3[b]) break; cur*=pot3[b]; if(cur>n/pot5[c]) break; cur*=pot5[c]; if(cur>n/pot7[d]) break; cur*=pot7[d]; m[cur]=brut(cur); //cout<<cur<<endl; //res++; //ctr++; } } } } //cout<<ctr<<endl; m[0]=0; int lgmax=0; ll tmp=q[0].first; while(tmp) { lgmax++; tmp/=10; } vector<map<ll, ll>>dpp(lgmax); for(int i=0; i<10; i++) dpp[0][i]=1; for(int i=1; i<lgmax; i++) { for(int j=0; j<10; j++) { for(auto x:dpp[i-1]) { if(dpp[i].find(x.first*j)==dpp[i].end()) dpp[i][x.first*j]=0; dpp[i][x.first*j]+=x.second; } } } for(int gg=0; gg<t; gg++) { //cout<<q[gg].first<<" "<<q[gg].second<<endl; //cout<<" G\n"; //ll res=0; n=q[gg].first; vector<ll>res(10, 0); if(n<10) { for(int i=1; i<=n; i++) res[i]=1; } else { vector<int>v; ll tmp=n; int lg=0; while(tmp) { lg++; v.push_back(tmp%10); tmp/=10; } //cout<<lg<<" lg\n"; res.clear(); res.resize(10, 1); res[0]=0; for(int k=1; k<lg-1; k++) { for(int i=1; i<10; i++) { for(auto x:dpp[k-1]) { res[m[x.first*i]]+=x.second; } } } for(int i=1; i<v[lg-1]; i++) { for(auto x:dpp[lg-2]) { res[m[x.first*i]]+=x.second; } } vector<map<ll, ll>>dp=dpp; /* for(auto y:dp) { for(auto x:y) cout<<x.first<<" "<<x.second<<endl; } cout<<" b\n"; */ for(int k=lg-1; k>0; k--) { //cout<<k<<endl; if(k==1) { dp[0].clear(); for(int j=0; j<=v[0]; j++) dp[0][j]=1; } else { dp[k-1].clear(); for(int j=0; j<v[k-1]; j++) { for(auto x:dp[k-2]) { if(dp[k-1].find(x.first*j)==dp[k-1].end()) dp[k-1][x.first*j]=0; dp[k-1][x.first*j]+=x.second; } } } //cout<<"zyw\n"; for(int i=k; i<lg; i++) { dp[i].clear(); for(auto x:dp[i-1]) { if(dp[i].find(x.first*v[i])==dp[i].end()) dp[i][x.first*v[i]]=0; dp[i][x.first*v[i]]+=x.second; } } for(auto x:dp[lg-2]) { //cout<<x.first<<" YO "<<x.second<<endl; res[m[x.first*v[lg-1]]]+=x.second; } } //res[brut(n)]++; } anss[q[gg].second]=res; } for(auto x:anss) { for(auto y:x) cout<<y<<" "; cout<<"\n"; } } |
English