A333773 Replace 2's with (-1)'s in ternary representation of n and sum nonzero terms with alternating signs.
0, 1, -1, 3, 2, 4, -3, -4, -2, 9, 8, 10, 6, 7, 5, 12, 13, 11, -9, -10, -8, -12, -11, -13, -6, -5, -7, 27, 26, 28, 24, 25, 23, 30, 31, 29, 18, 19, 17, 21, 20, 22, 15, 14, 16, 36, 37, 35, 39, 38, 40, 33, 32, 34, -27, -28, -26, -30, -29, -31, -24, -23, -25, -36
Offset: 0
Examples
For n = 97: - 97 = 3^4 + 3^2 + 2*3^1 + 3^0, - hence a(97) = 3^4 - 3^2 + (-1)*3^1 - 3^0 = 68.
Links
- Rémy Sigrist, Table of n, a(n) for n = 0..6561
Programs
-
PARI
a(n) = { my (v=0, t=Vecrev(digits(n,3))); for (k=1, #t, if (t[k]==1, v=+3^(k-1)-v, t[k]==2, v=-3^(k-1)-v)); v }
Comments