login

Reminder: The OEIS is hiring a new managing editor, and the application deadline is January 26.

a(n) is the number of terms in the mixed binary-ternary representation of n. See Comments.
3

%I #26 Jan 28 2025 00:49:32

%S 1,1,1,1,2,1,2,1,1,2,2,2,2,3,2,1,2,1,2,2,2,2,3,2,3,2,1,2,2,2,2,1,2,2,

%T 2,2,3,2,3,2,2,3,3,3,3,4,3,2,3,2,3,3,3,1,2,2,2,2,3,2,3,2,2,1,2,2,2,2,

%U 3,2,3,2,2,3,3,3,3,4,3,2,1,2,2,2,2,3

%N a(n) is the number of terms in the mixed binary-ternary representation of n. See Comments.

%C Suppose that B1 and B2 are increasing sequences of positive integers, and let B be the increasing sequence of numbers in the union of B1 and B2. Every positive integer n has a unique representation given by the greedy algorithm with B1 as base, and likewise for B2 and B. For many n, the number of terms in the B-representation of n is less than the number of terms in the B1-representation, as well as the B2-representation, but not for all n, as in the example 45 = 27 + 18 (ternary) and 45 = 32 + 9 + 4 (mixed).

%H Michael S. Branicky, <a href="/A336005/b336005.txt">Table of n, a(n) for n = 1..10000</a>

%e 7 = 6 + 1, so a(7) = 2.

%e 45 = 32 + 9 + 4, so a(45) = 3.

%t z = 20; zz = 100;

%t b1 = Sort[Table[2^k, {k, 0, z}], Greater];

%t b2 = Sort[Union[Table[3^k, {k, 0, z}], Table[2*3^k, {k, 0, z}]],

%t Greater]; b = Sort[Union[b1, b2], Greater];

%t g1 = Map[{#, DeleteCases[b1 Reap[

%t FoldList[(Sow[Quotient[#1, #2]]; Mod[#1, #2]) &, #, b1]][[2,

%t 1]], 0]} &, Range[zz]];

%t m1 = Map[Length[#[[2]]] &, g1];

%t g2 = Map[{#, DeleteCases[b2 Reap[FoldList[(Sow[Quotient[#1, #2]]; Mod[#1, #2]) &, #, b2]][[2, 1]], 0]} &, Range[zz]];

%t m2 = Map[Length[#[[2]]] &, g2];

%t g = Map[{#, DeleteCases[

%t b Reap[FoldList[(Sow[Quotient[#1, #2]]; Mod[#1, #2]) &, #,

%t b]][[2, 1]], 0]} &, Range[zz]]

%t m = Map[Length[#[[2]]] &, g];

%t m1 (* # terms in binary representation *)

%t m2 (* # terms in ternary representation *)

%t m (* # terms in mixed base representation *) (* A336005 *)

%o (Python)

%o from itertools import count, takewhile

%o N = 10**6

%o B1 = list(takewhile(lambda x: x[0] <= N, ((2**i, 2) for i in count(0))))

%o B21 = list(takewhile(lambda x: x[0] <= N, ((3**i, 3) for i in count(0))))

%o B22 = list(takewhile(lambda x: x[0] <= N, ((2*3**i, 3) for i in count(0))))

%o B = sorted(set(B1 + B21 + B22), reverse=True)

%o def gbt(n, B): # greedy binary-ternary representation

%o r = []

%o for t, b in B:

%o if t <= n:

%o r.append(t)

%o n -= t

%o if n == 0:

%o return r

%o def a(n): return len(gbt(n, B))

%o print([a(n) for n in range(1, 87)]) # _Michael S. Branicky_, Jan 06 2022

%Y Cf. A336004, A336006.

%K nonn,base,changed

%O 1,5

%A _Clark Kimberling_, Jul 06 2020