login
A339601
Starting from x_0 = n, iterate by dividing with 3 (discarding any remainder), until zero is reached: x_1 = floor(x_0/3), x_2 = floor(x_1/3), etc. Then a(n) = Sum_{i=0..} (x_i AND 2^i), where AND is bitwise-and.
2
0, 1, 0, 1, 0, 1, 2, 3, 2, 3, 2, 3, 0, 1, 0, 1, 0, 1, 2, 3, 2, 3, 2, 3, 0, 1, 0, 1, 0, 1, 2, 3, 2, 3, 2, 3, 4, 5, 4, 5, 4, 5, 6, 7, 6, 7, 6, 7, 4, 5, 4, 5, 4, 5, 6, 7, 6, 7, 6, 7, 4, 5, 4, 5, 4, 5, 6, 7, 6, 7, 6, 7, 0, 1, 0, 1, 0, 1, 2, 3, 2, 3, 2, 3, 0, 1, 0, 1, 0, 1, 2, 3, 2, 3, 2, 3, 0, 1, 0, 1, 0, 1, 2, 3, 2, 3
OFFSET
0,7
MATHEMATICA
Array[Total@ MapIndexed[BitAnd[2^First[#2 - 1], #1] &, NestWhileList[Floor[#/3] &, #, # > 0 &]] &, 106, 0] (* Michael De Vlieger, Dec 10 2020 *)
PROG
(PARI) A339601(n) = { my(i=0, s=0); while(n, s += bitand(2^i, n); i++; n \= 3); (s); };
(PARI) A339601(n) = { my(m=1, s=0); while(n>=m, s += bitand(m, n); m <<= 1; n \= 3); (s); };
CROSSREFS
Cf. also A332497.
Sequence in context: A066102 A036048 A145384 * A117666 A274921 A274821
KEYWORD
nonn,base
AUTHOR
Antti Karttunen, Dec 09 2020
STATUS
approved