login
A binary encoding of the zeros in ternary representation of n.
10

%I #20 May 15 2021 06:18:08

%S 0,0,1,0,0,1,0,0,3,2,2,1,0,0,1,0,0,3,2,2,1,0,0,1,0,0,7,6,6,5,4,4,5,4,

%T 4,3,2,2,1,0,0,1,0,0,3,2,2,1,0,0,1,0,0,7,6,6,5,4,4,5,4,4,3,2,2,1,0,0,

%U 1,0,0,3,2,2,1,0,0,1,0,0,15,14,14,13,12,12,13,12,12,11,10,10,9,8,8,9,8,8,11,10,10,9,8,8,9,8,8,7,6,6

%N A binary encoding of the zeros in ternary representation of n.

%C 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).

%H Antti Karttunen, <a href="/A291770/b291770.txt">Table of n, a(n) for n = 1..59049</a>

%F For all n >= 0, a(A000244(n)) = A000225(n), that is, a(3^n) = (2^n) - 1. [The records in the sequence].

%F For all n >= 1, A000120(a(n)) = A077267(n).

%F For all n >= 1, A278222(a(n)) = A291771(n).

%e n a(n) ternary(n) binary(a(n))

%e A007089(n) A007088(a(n))

%e -- ---- ---------- ------------

%e 1 0 1 0

%e 2 0 2 0

%e 3 1 10 1

%e 4 0 11 0

%e 5 0 12 0

%e 6 1 20 1

%e 7 0 21 0

%e 8 0 22 0

%e 9 3 100 11

%e 10 2 101 10

%e 11 2 102 10

%e 12 1 110 1

%e 13 0 111 0

%e 14 0 112 0

%e 15 1 120 1

%e 16 0 121 0

%e 17 0 122 0

%e 18 3 200 11

%e 19 2 201 10

%e 20 2 202 10

%e 21 1 210 1

%e 22 0 211 0

%e 23 0 212 0

%e 24 1 220 1

%e 25 0 221 0

%e 26 0 222 0

%e 27 7 1000 111

%e 28 6 1001 110

%e 29 6 1002 110

%e 30 5 1010 101

%t Table[FromDigits[IntegerDigits[n, 3] /. k_ /; k < 3 :> If[k == 0, 1, 0], 2], {n, 110}] (* _Michael De Vlieger_, Sep 11 2017 *)

%o (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)))))))

%o (Python)

%o from sympy.ntheory.factor_ import digits

%o def a(n):

%o k=digits(n, 3)[1:]

%o return int("".join('1' if i==0 else '0' for i in k), 2)

%o print([a(n) for n in range(1, 111)]) # _Indranil Ghosh_, Sep 21 2017

%Y Cf. A007088, A007089, A077267, A289813, A289814, A291771.

%K nonn,base

%O 1,9

%A _Antti Karttunen_, Sep 11 2017