login
a(0) = 0, and for any n > 0, a(3*n) = 3*a(n), a(3*n+1) = 1-3*a(n), a(3*n+2) = 2-3*a(n).
2

%I #12 Jul 18 2022 14:16:41

%S 0,1,2,3,-2,-1,6,-5,-4,9,-8,-7,-6,7,8,-3,4,5,18,-17,-16,-15,16,17,-12,

%T 13,14,27,-26,-25,-24,25,26,-21,22,23,-18,19,20,21,-20,-19,24,-23,-22,

%U -9,10,11,12,-11,-10,15,-14,-13,54,-53,-52,-51,52,53,-48,49

%N a(0) = 0, and for any n > 0, a(3*n) = 3*a(n), a(3*n+1) = 1-3*a(n), a(3*n+2) = 2-3*a(n).

%C This sequence establishes a bijection from the nonnegative integers (N) to the integers (Z).

%C This sequence is to base 3 what A065620 is to base 2.

%C To compute a(n): write n as a sum of terms of A038754 with distinct 3-adic valuations and take the alternating sum.

%H Rémy Sigrist, <a href="/A355624/b355624.txt">Table of n, a(n) for n = 0..6561</a>

%F a(n) = n iff n = 0 or n belongs to A038754.

%e For n = 107:

%e 107 = 3^4 + 2*3^2 + 2*3^1 + 2*3^0,

%e so a(107) = -3^4 + 2*3^2 - 2*3^1 + 2*3^0 = -67.

%o (PARI) a(n, base=3) = { my (d=digits(n, base), s=1); forstep (k=#d, 1, -1, if (d[k], d[k]*=s; s=-s)); return (fromdigits(d, base)) }

%Y Cf. A038754, A065620, A355675.

%K sign,base,easy

%O 0,3

%A _Rémy Sigrist_, Jul 14 2022