login
A355624
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
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, 13, 14, 27, -26, -25, -24, 25, 26, -21, 22, 23, -18, 19, 20, 21, -20, -19, 24, -23, -22, -9, 10, 11, 12, -11, -10, 15, -14, -13, 54, -53, -52, -51, 52, 53, -48, 49
OFFSET
0,3
COMMENTS
This sequence establishes a bijection from the nonnegative integers (N) to the integers (Z).
This sequence is to base 3 what A065620 is to base 2.
To compute a(n): write n as a sum of terms of A038754 with distinct 3-adic valuations and take the alternating sum.
LINKS
FORMULA
a(n) = n iff n = 0 or n belongs to A038754.
EXAMPLE
For n = 107:
107 = 3^4 + 2*3^2 + 2*3^1 + 2*3^0,
so a(107) = -3^4 + 2*3^2 - 2*3^1 + 2*3^0 = -67.
PROG
(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)) }
CROSSREFS
KEYWORD
sign,base,easy
AUTHOR
Rémy Sigrist, Jul 14 2022
STATUS
approved