OFFSET
1,9
COMMENTS
The ones in the binary representation of a(n) correspond to the nonleading zeros in the ternary representation of n. For example: ternary(33) = 1020 and binary(a(33)) = 101 (a(33) = 5).
LINKS
Antti Karttunen, Table of n, a(n) for n = 1..59049
FORMULA
EXAMPLE
n a(n) ternary(n) binary(a(n))
-- ---- ---------- ------------
1 0 1 0
2 0 2 0
3 1 10 1
4 0 11 0
5 0 12 0
6 1 20 1
7 0 21 0
8 0 22 0
9 3 100 11
10 2 101 10
11 2 102 10
12 1 110 1
13 0 111 0
14 0 112 0
15 1 120 1
16 0 121 0
17 0 122 0
18 3 200 11
19 2 201 10
20 2 202 10
21 1 210 1
22 0 211 0
23 0 212 0
24 1 220 1
25 0 221 0
26 0 222 0
27 7 1000 111
28 6 1001 110
29 6 1002 110
30 5 1010 101
MATHEMATICA
Table[FromDigits[IntegerDigits[n, 3] /. k_ /; k < 3 :> If[k == 0, 1, 0], 2], {n, 110}] (* Michael De Vlieger, Sep 11 2017 *)
PROG
(Scheme) (define (A291770 n) (if (zero? n) n (let loop ((n n) (b 1) (s 0)) (if (< n 3) s (let ((d (modulo n 3))) (if (zero? d) (loop (/ n 3) (+ b b) (+ s b)) (loop (/ (- n d) 3) (+ b b) s)))))))
(Python)
from sympy.ntheory.factor_ import digits
def a(n):
k=digits(n, 3)[1:]
return int("".join('1' if i==0 else '0' for i in k), 2)
print([a(n) for n in range(1, 111)]) # Indranil Ghosh, Sep 21 2017
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Antti Karttunen, Sep 11 2017
STATUS
approved