login
Replace 6^k with (-1)^k in base-6 expansion of n.
9

%I #19 Nov 22 2022 22:19:18

%S 0,1,2,3,4,5,-1,0,1,2,3,4,-2,-1,0,1,2,3,-3,-2,-1,0,1,2,-4,-3,-2,-1,0,

%T 1,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,0,1,2,3,4,5,-1,0,1,2,3,4,-2,-1,0,1,2,

%U 3,-3,-2,-1,0,1,2,-4,-3,-2,-1,0,1,2,3,4,5,6,7,1,2,3,4,5,6,0,1,2,3,4,5,-1,0,1,2,3,4,-2,-1,0,1,2,3,-3,-2,-1

%N Replace 6^k with (-1)^k in base-6 expansion of n.

%C If n has base-6 expansion abc..xyz with least significant digit z, a(n) = z - y + x - w + ...

%H Robert Israel, <a href="/A346690/b346690.txt">Table of n, a(n) for n = 0..10000</a>

%F G.f. A(x) satisfies: A(x) = x * (1 + 2*x + 3*x^2 + 4*x^3 + 5*x^4) / (1 - x^6) - (1 + x + x^2 + x^3 + x^4 + x^5) * A(x^6).

%F a(n) = n + 7 * Sum_{k>=1} (-1)^k * floor(n/6^k).

%F a(6*n+j) = j - a(n) for 0 <= j <= 5. - _Robert Israel_, Nov 21 2022

%e 59 = 135_6, 5 - 3 + 1 = 3, so a(59) = 3.

%p f:= proc(n) option remember; (n mod 6) - procname(floor(n/6)) end proc:

%p f(0):= 0:

%p map(f, [$1..100]); # _Robert Israel_, Nov 21 2022

%t nmax = 104; A[_] = 0; Do[A[x_] = x (1 + 2 x + 3 x^2 + 4 x^3 + 5 x^4)/(1 - x^6) - (1 + x + x^2 + x^3 + x^4 + x^5) A[x^6] + O[x]^(nmax + 1) // Normal, nmax + 1]; CoefficientList[A[x], x]

%t Table[n + 7 Sum[(-1)^k Floor[n/6^k], {k, 1, Floor[Log[6, n]]}], {n, 0, 104}]

%o (Python)

%o from sympy.ntheory.digits import digits

%o def a(n):

%o return sum(bi*(-1)**k for k, bi in enumerate(digits(n, 6)[1:][::-1]))

%o print([a(n) for n in range(105)]) # _Michael S. Branicky_, Jul 29 2021

%o (PARI) a(n) = subst(Pol(digits(n, 6)), 'x, -1); \\ _Michel Marcus_, Nov 22 2022

%Y Cf. A007092, A053827, A055017, A065359, A065368, A346688, A346689, A346691.

%K sign,base,easy

%O 0,3

%A _Ilya Gutkovskiy_, Jul 29 2021