%I #39 Apr 10 2026 14:28:12
%S 1,1,1,4,6,2,27,51,30,6,256,568,456,168,24,3125,7845,7780,4020,1080,
%T 120,46656,129456,150480,97920,37440,7920,720,823543,2485567,3279234,
%U 2537850,1235640,375480,65520,5040,16777216,54442368,79775360,70885248,41408640,16141440,4072320,604800,40320
%N Triangle read by rows: Expansion of the e.g.f. 1/( 1 + (1+y)*LambertW(-x) ).
%C T(n,k)/n^n is the expected value of C(F_n,k), where the random variable F_n is the number of rolls of a fair n-sided die before the first repeated face.
%C Consider an endofunction as a digraph (comprised of a set of cycles, with each cyclic element being the root of a tree of non-cyclic preimages), then T(n,k) is the number of endofunctions [n]->[n] with k trees painted blue and the rest painted red.
%H Philippe Flajolet, Peter J. Grabner, Peter Kirschenhofer, and Helmut Prodinger, <a href="https://doi.org/10.1016/0377-0427(93)E0258-N">On Ramanujan's Q-function</a>, Journal of Computational and Applied Mathematics, vol. 58, iss. 1 (1995-03-20), pp. 103-116.
%H Natalia L. Skirrow, <a href="https://math.stackexchange.com/q/5131153">decomposing the binomial moments of (# distinct faces seen rolling n-sided die before first repetition)</a>, Mathematics StackExchange, 2026.
%H Natalia L. Skirrow, <a href="/wiki/User:Natalia_L._Skirrow/Euler's_tree_function">Euler's tree function</a>.
%H Wikipedia, <a href="https://en.wikipedia.org/wiki/Lambert_W_function">Lambert W function</a>.
%F T(n,k) = Sum_{j=k..n} A066324(n,j) * C(j,k).
%F E.g.f.: 1/(1-(1+y)*T(x)) where T(x) satisfies T=x*e^T. (T(x) is A000169's e.g.f. and equals -W(-x) where W is the Lambert W).
%F E.g.f. is F(x,1+y), where F(x,y) is A066324's e.g.f.
%F E.g.f. for T(n,k)/n (for n>0): T + (1-1/(1+y))*log(1/(1-(1+y)*T)).
%F E.g.f. for T(n,k)/n is G(x,1+y), where G(x,y) = T+(1-1/y)*C(x,y) is A259334's e.g.f. and C(x,y)=log(1/(1-y*T)) is A201685's.
%F For row o.g.f., replace y with 1+y in that of A066324.
%F Let Q(n) = Sum_{k=1..n} n!/((n-k)!*n^k) ~ sqrt(Pi*n/2) be Ramanujan's Q function.
%F T(n,k) = n^(n-k) * hypergeometric([k-n,k],[],-1/n) * n!/(n-k)!.
%F T(n,k) = A394824(n,k)*n!/(n-k)!. - _Peter Luschny_, Apr 04 2026
%F T(n,0) = A000312(n) = n*A000169(n) = n^n. (Row sums)
%F T(n,1) = A063169(n) = n*A001865(n) = n^n*Q(n).
%F T(n,2) = A219706(n) = n*A185391(n-1)=n^n*(n - Q(n)).
%F T(n,3) = n^n*((n+2)*Q(n) - 3*n)/2.
%F In general, T(n,k)/n^n = A_k(n)*Q(n) + B_k(n), with A_k,B_k polynomials of degree ceiling(k/2)-1 and floor(k/2), with:
%F A_k(n) = Sum_{j=0..k-1}(-n)^j/j! * C(n-1-j,k-1-j).
%F B_k(n) = n*Sum_{j=0..m-2}(-n)^j/j! * Sum_{k=0..m-2-j} C(n-1,k)*C(m-2-k,j)*(-1)^(m-j-k)/(j+k+1).
%F Both A_k and B_k abide by the recurrence k*P_{k+1}(n) = (1-2*k)*P_k(n) + (n+1-k)*P_{k-1}(n).
%F From _Peter Luschny_, Apr 09 2026: (Start)
%F T(n, k) = ((2*k + 1)*T(n, k+1) + (k + 1)*T(n, k+2))/(n - k) with T(n, n) = n!.
%F Let egf(x, y) = exp(x * (1 + y) * exp(y / (1 + y))) / (1 + y), then
%F T(n, k) = (n!)^2 * [x^n y^(n-k)] egf(x, y). (End)
%e Triangle begins:
%e n\k 0 1 2 3 4 5 6 7
%e -+--------------------------------------------------------
%e 0| 1
%e 1| 1 1
%e 2| 4 6 2
%e 3| 27 51 30 6
%e 4| 256 568 456 168 24
%e 5| 3125 7845 7780 4020 1080 120
%e 6| 46656 129456 150480 97920 37440 7920 720
%e 7|823543 2485567 3279234 2537850 1235640 375480 65520 5040
%p A394852 := (n, k) -> A394824(n, k)*n!/(n - k)!:
%p seq(print(seq(simplify(A394852(n, k)), k = 0..n)), n = 0..9); # _Peter Luschny_, Apr 04 2026
%p # Alternative:
%p egf := (1 + (y + 1) * LambertW(-x))^(-1): ser := series(egf, x, 9): xcoeff := n -> coeff(ser, x, n): seq(print(seq(n! * coeff(xcoeff(n), y, k), k = 0..n)), n = 0..7); # _Peter Luschny_, Apr 06 2026
%t nMax = 8; egf = Exp[x*(1 + y)*Exp[y/(1 + y)]] / (1 + y);
%t coeffs = Series[egf, {x, 0, nMax+1}, {y, 0, nMax+1}] // Normal;
%t Table[(n!)^2 * Coefficient[Coefficient[coeffs, x, n], y, n - k], {n, 0, nMax}, {k, 0, n}] // Flatten (* _Peter Luschny_, Apr 09 2026 *)
%o (Python)
%o from math import factorial
%o def A394852row(n: int) -> list[int]:
%o if n == 0: return [1]
%o row = [0] * (n + 1)
%o row[n] = curr = factorial(n)
%o ahead = 0
%o for k in range(n, 0, -1):
%o prev = ((2 * k - 1) * curr + k * ahead) // (n - k + 1)
%o row[k - 1] = prev
%o ahead, curr = curr, prev
%o return row
%o for n in range(0, 8): print(A394852row(n)) # _Peter Luschny_, Apr 09 2026
%Y Columns k=0..2 give: A000312, A063169, A219706.
%Y Columns / n: A000169, A001865, A185391.
%Y Cf. A000169, A201685, A259334.
%K nonn,tabl
%O 0,4
%A _Natalia L. Skirrow_, Apr 04 2026