#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef unordered_map<LL, LL> MAP;
inline LL compute_mdr(LL n)
{
while (n > 9)
{
LL prod = 1;
while (n)
{
prod *= n % 10ll;
n /= 10ll;
}
n = prod;
}
return n;
}
inline int discrete_log(LL n)
{
int res = 0;
while (n)
{
n /= 10;
++res;
}
return res;
}
inline void solve(LL n, const vector<vector<MAP>> &cnt, const vector<MAP> &pospref, MAP &mdr)
{
int l = discrete_log(n);
LL p = 1e18;
while (!(n / p)) p /= 10;
vector<LL> res(10);
++res[compute_mdr(n)];
MAP possible = pospref[l - 1];
for (auto &[x, y] : cnt[l][0]) possible[x] -= y;
LL pref = 1ll;
for (int pos = l; pos; --pos)
{
LL d = n / p;
if (d)
{
for (auto &[x, y] : cnt[pos][d - 1]) possible[pref * x] += y;
}
pref *= d;
n -= d * p;
p /= 10;
}
for (auto &[x, y] : possible)
{
if (!mdr.count(x)) mdr[x] = compute_mdr(x);
res[mdr[x]] += y;
}
for (LL r : res) cout << r << " ";
cout << "\n";
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
vector<vector<MAP>> cnt(19, vector<MAP>(10));
vector<MAP> pospref(19);
MAP mdr;
cnt[0][1][1] = 1;
for (int l = 1; l < 9; ++l)
{
for (auto &[x, y] : cnt[0][l])
{
cnt[0][l + 1][x] += y;
}
}
for (int d = 1; d <= 18; ++d)
{
for (int l = 0; l < 10; ++l)
{
for (auto &[x, y] : cnt[d - 1][9])
{
cnt[d][l][l * x] += y;
}
}
for (int l = 0; l < 9; ++l)
{
for (auto &[x, y] : cnt[d][l])
{
cnt[d][l + 1][x] += y;
}
}
}
for (int d = 1; d <= 18; ++d)
{
pospref[d] = cnt[d][9];
for (auto &[x, y] : cnt[d][0])
{
pospref[d][x] -= y;
}
for (auto &[x, y] : pospref[d - 1])
{
pospref[d][x] += y;
}
}
LL t, n;
cin >> t;
while (t--)
{
cin >> n;
solve(n, cnt, pospref, mdr);
}
}
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 | #include <iostream> #include <vector> #include <algorithm> #include <string> #include <unordered_map> using namespace std; typedef long long LL; typedef unordered_map<LL, LL> MAP; inline LL compute_mdr(LL n) { while (n > 9) { LL prod = 1; while (n) { prod *= n % 10ll; n /= 10ll; } n = prod; } return n; } inline int discrete_log(LL n) { int res = 0; while (n) { n /= 10; ++res; } return res; } inline void solve(LL n, const vector<vector<MAP>> &cnt, const vector<MAP> &pospref, MAP &mdr) { int l = discrete_log(n); LL p = 1e18; while (!(n / p)) p /= 10; vector<LL> res(10); ++res[compute_mdr(n)]; MAP possible = pospref[l - 1]; for (auto &[x, y] : cnt[l][0]) possible[x] -= y; LL pref = 1ll; for (int pos = l; pos; --pos) { LL d = n / p; if (d) { for (auto &[x, y] : cnt[pos][d - 1]) possible[pref * x] += y; } pref *= d; n -= d * p; p /= 10; } for (auto &[x, y] : possible) { if (!mdr.count(x)) mdr[x] = compute_mdr(x); res[mdr[x]] += y; } for (LL r : res) cout << r << " "; cout << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); vector<vector<MAP>> cnt(19, vector<MAP>(10)); vector<MAP> pospref(19); MAP mdr; cnt[0][1][1] = 1; for (int l = 1; l < 9; ++l) { for (auto &[x, y] : cnt[0][l]) { cnt[0][l + 1][x] += y; } } for (int d = 1; d <= 18; ++d) { for (int l = 0; l < 10; ++l) { for (auto &[x, y] : cnt[d - 1][9]) { cnt[d][l][l * x] += y; } } for (int l = 0; l < 9; ++l) { for (auto &[x, y] : cnt[d][l]) { cnt[d][l + 1][x] += y; } } } for (int d = 1; d <= 18; ++d) { pospref[d] = cnt[d][9]; for (auto &[x, y] : cnt[d][0]) { pospref[d][x] -= y; } for (auto &[x, y] : pospref[d - 1]) { pospref[d][x] += y; } } LL t, n; cin >> t; while (t--) { cin >> n; solve(n, cnt, pospref, mdr); } } |
English