#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include <bits/stdc++.h>
#define FOR(i,p,k) for(int i=(p); i<=(k); ++i)
#define REP(i,k) FOR(i,0,(k)-1)
#define RFOR(i,p,n) for(int i=(p); i>=(n); --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ssize(x) int((x).size())
#define fi first
#define se second
#define V vector
#define pb push_back
#define eb emplace_back
#define C const
#define pn printf("\n")
using namespace std;
typedef long long ll;
typedef V <int> vi;
typedef V <ll> vll;
typedef C int ci;
typedef C ll cll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
void chmin(auto &a, auto b){a=min(a,b);}
void chmax(auto &a, auto b){a=max(a,b);}
ci inf=2.1e9;
cll infll=4.5e18;
int I(){
int z;
scanf("%d", &z);
//cin>>z;
return z;
}
ll LL(){
ll z;
scanf("%lld", &z);
//cin>>z;
return z;
}
void ans(){
struct stant{
int nast[10];
int wygr;
ll liczba;
};
struct wynt{
ll t[10];
wynt(){
memset(t, 0x00, sizeof(t));
}
ll &operator[](ci i){
return t[i];
}
cll &operator[](ci i) C{
return t[i];
}
void operator+=(C wynt &i){
REP(cyf, 10)
t[cyf]+=i[cyf];
}
};
static map <ll, int> mstan;
static int ilestan=1;
static V <stant> stany;
static ci cyfcap=18;
static V <V <wynt>> prpdokon;
static bool czyinit=0;
if (!czyinit){
czyinit=1;
mstan[0]=0;
// stan=0 to zerujący się na pewno.
stany.eb();
memset(&stany.back(), 0x00, sizeof(stant));
C vi capt={60, 38, 26, 22};
ll t[capt[0]+1][capt[1]+1][capt[2]+1][capt[3]+1];
t[0][0][0][0]=1;
cll cap=1e18; // ig? co z ifem na 1e18?
REP(a, capt[0]) REP(b, capt[1]) REP(c, capt[2]) REP(d, capt[3]){
cll l=t[a][b][c][d];
if (l>cap||!l)
continue;
if (a&&c)
mstan[l]=0;
else{
mstan[l]=ilestan++;
stany.eb();
stany.back().liczba=l;
}
t[a+1][b][c][d]=l*2;
t[a][b+1][c][d]=l*3;
t[a][b][c+1][d]=l*5;
t[a][b][c][d+1]=l*7;
}
assert(stany[1].liczba==1);
FOR(i, 1, ilestan-1)
REP(cyf, 10){
cll l=stany[i].liczba*cyf;
if (!mstan.contains(l))
stany[i].nast[cyf]=-1; // ig?
else
stany[i].nast[cyf]=mstan[l];
}
{
vll v;
REP(i, ilestan)
v.eb(stany[i].liczba);
sort(all(v));
for (cll l : v){
ll ilcyf=1;
{
ll p=l;
if (!p)
ilcyf=0;
while (p)
ilcyf*=p%10,p/=10;
}
assert(ilcyf<l||l<10);
stany[mstan[l]].wygr=l<10 ? int(l) : stany[mstan[ilcyf]].wygr;
}
}
prpdokon.resize(cyfcap+1, V <wynt>(ilestan));
REP(i, ilestan)
prpdokon[0][i][stany[i].wygr]=1;
FOR(a, 1, cyfcap)
REP(i, ilestan)
REP(cyf, 10)
if (stany[i].nast[cyf]>=0)
prpdokon[a][i]+=prpdokon[a-1][stany[i].nast[cyf]]; // 18*10*10*ilestan
}
ll _n=LL();
wynt w;
if (_n==ll(1e18))
--_n,w[0]=1;
cll n=_n;
int ncyf=0;
vi cyfv;
{
ll l=n;
while (l)
cyfv.eb(l%10),l/=10,++ncyf;
}
// NOTE: WARNING: ERROR: TODO: zero może potrzebować wyifowania jakiegoś ig????
// tutaj przynajmniej go nie wliczymy.
// mniej cyfr jak n.
FOR(cyf, 1, ncyf-1)
FOR(poczcyf, 1, 9)
w+=prpdokon[cyf-1][mstan[poczcyf]];
int st=1;
FOR(cyfrow, 0, ncyf-1){ // że cyfrow równe, a pierwsza kolejna <.
ci nc=cyfv[ncyf-cyfrow-1];
FOR(nowcyf, !cyfrow, nc-1)
w+=prpdokon[ncyf-cyfrow-1][stany[st].nast[nowcyf]];
st=stany[st].nast[nc];
}
// doliczamy n?
++w[stany[st].wygr];
printf("%lld", w[0]);
FOR(i, 1, 9)
printf(" %lld", w[i]);
pn;
}
int main(){
//ios_base::sync_with_stdio(0),cin.tie(0);
int tt=1;
tt=I();
while (tt--)ans();
}
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 | #ifndef LOCAL #pragma GCC optimize("O3") #endif #include <bits/stdc++.h> #define FOR(i,p,k) for(int i=(p); i<=(k); ++i) #define REP(i,k) FOR(i,0,(k)-1) #define RFOR(i,p,n) for(int i=(p); i>=(n); --i) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define ssize(x) int((x).size()) #define fi first #define se second #define V vector #define pb push_back #define eb emplace_back #define C const #define pn printf("\n") using namespace std; typedef long long ll; typedef V <int> vi; typedef V <ll> vll; typedef C int ci; typedef C ll cll; typedef pair <int, int> pii; typedef pair <ll, ll> pll; void chmin(auto &a, auto b){a=min(a,b);} void chmax(auto &a, auto b){a=max(a,b);} ci inf=2.1e9; cll infll=4.5e18; int I(){ int z; scanf("%d", &z); //cin>>z; return z; } ll LL(){ ll z; scanf("%lld", &z); //cin>>z; return z; } void ans(){ struct stant{ int nast[10]; int wygr; ll liczba; }; struct wynt{ ll t[10]; wynt(){ memset(t, 0x00, sizeof(t)); } ll &operator[](ci i){ return t[i]; } cll &operator[](ci i) C{ return t[i]; } void operator+=(C wynt &i){ REP(cyf, 10) t[cyf]+=i[cyf]; } }; static map <ll, int> mstan; static int ilestan=1; static V <stant> stany; static ci cyfcap=18; static V <V <wynt>> prpdokon; static bool czyinit=0; if (!czyinit){ czyinit=1; mstan[0]=0; // stan=0 to zerujący się na pewno. stany.eb(); memset(&stany.back(), 0x00, sizeof(stant)); C vi capt={60, 38, 26, 22}; ll t[capt[0]+1][capt[1]+1][capt[2]+1][capt[3]+1]; t[0][0][0][0]=1; cll cap=1e18; // ig? co z ifem na 1e18? REP(a, capt[0]) REP(b, capt[1]) REP(c, capt[2]) REP(d, capt[3]){ cll l=t[a][b][c][d]; if (l>cap||!l) continue; if (a&&c) mstan[l]=0; else{ mstan[l]=ilestan++; stany.eb(); stany.back().liczba=l; } t[a+1][b][c][d]=l*2; t[a][b+1][c][d]=l*3; t[a][b][c+1][d]=l*5; t[a][b][c][d+1]=l*7; } assert(stany[1].liczba==1); FOR(i, 1, ilestan-1) REP(cyf, 10){ cll l=stany[i].liczba*cyf; if (!mstan.contains(l)) stany[i].nast[cyf]=-1; // ig? else stany[i].nast[cyf]=mstan[l]; } { vll v; REP(i, ilestan) v.eb(stany[i].liczba); sort(all(v)); for (cll l : v){ ll ilcyf=1; { ll p=l; if (!p) ilcyf=0; while (p) ilcyf*=p%10,p/=10; } assert(ilcyf<l||l<10); stany[mstan[l]].wygr=l<10 ? int(l) : stany[mstan[ilcyf]].wygr; } } prpdokon.resize(cyfcap+1, V <wynt>(ilestan)); REP(i, ilestan) prpdokon[0][i][stany[i].wygr]=1; FOR(a, 1, cyfcap) REP(i, ilestan) REP(cyf, 10) if (stany[i].nast[cyf]>=0) prpdokon[a][i]+=prpdokon[a-1][stany[i].nast[cyf]]; // 18*10*10*ilestan } ll _n=LL(); wynt w; if (_n==ll(1e18)) --_n,w[0]=1; cll n=_n; int ncyf=0; vi cyfv; { ll l=n; while (l) cyfv.eb(l%10),l/=10,++ncyf; } // NOTE: WARNING: ERROR: TODO: zero może potrzebować wyifowania jakiegoś ig???? // tutaj przynajmniej go nie wliczymy. // mniej cyfr jak n. FOR(cyf, 1, ncyf-1) FOR(poczcyf, 1, 9) w+=prpdokon[cyf-1][mstan[poczcyf]]; int st=1; FOR(cyfrow, 0, ncyf-1){ // że cyfrow równe, a pierwsza kolejna <. ci nc=cyfv[ncyf-cyfrow-1]; FOR(nowcyf, !cyfrow, nc-1) w+=prpdokon[ncyf-cyfrow-1][stany[st].nast[nowcyf]]; st=stany[st].nast[nc]; } // doliczamy n? ++w[stany[st].wygr]; printf("%lld", w[0]); FOR(i, 1, 9) printf(" %lld", w[i]); pn; } int main(){ //ios_base::sync_with_stdio(0),cin.tie(0); int tt=1; tt=I(); while (tt--)ans(); } |
English