OFFSET
0,5
FORMULA
T(n,k) = T(n-1,k/2) for k being even.
T(n,k) = 3*T(n-1,(k-1)/2) + 2^(n-1) for k being odd.
T(n,k) = 2*T(n-1,k) for 0 <= k <= 2^(n-1) - 1.
T(n,k) = Sum_{i=0..r} 2^(n-1-e[i]) * 3^i where binary expansion k = 2^e[0] + 2^e[1] + ... + 2^e[r] with ascending e[0] < e[1] < ... < e[r] (A133457). - Kevin Ryde, Oct 22 2021
EXAMPLE
n\k 0 1 2 3 4 5 6 7
0 0
1 0 1
2 0 2 1 5
3 0 4 2 10 1 7 5 19
MATHEMATICA
T[0, 0] = 0; T[n_, k_] := T[n, k] = If[EvenQ[k], T[n - 1, k/2], 3*T[n - 1, (k - 1)/2] + 2^(n - 1)]; Table[T[n, k], {n, 0, 5}, {k, 0, 2^n - 1}] // Flatten (* Amiram Eldar, Oct 11 2021 *)
PROG
(PARI) T(n, k) = if ((n==0) && (k==0), 0, if (k%2, 3*T(n-1, (k-1)/2) + 2^(n-1), T(n-1, k/2)));
tabf(nn) = for (n=0, nn, for (k=0, 2^n-1, print1(T(n, k), ", ")); print); \\ Michel Marcus, Oct 18 2021
(PARI) T(n, k) = my(ret=0); for(i=0, n-1, if(bittest(k, n-1-i), ret=3*ret+1<<i)); ret; \\ Kevin Ryde, Oct 22 2021
CROSSREFS
KEYWORD
nonn,tabf
AUTHOR
Ryan Brooks, Oct 04 2021
STATUS
approved