login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

A352502
a(n) is the number of integers k in the interval 0..n such that k and n-k can be added without carries in balanced ternary.
2
1, 2, 2, 4, 4, 2, 4, 4, 6, 10, 8, 6, 10, 8, 2, 4, 4, 6, 10, 8, 6, 10, 8, 10, 16, 12, 18, 28, 20, 14, 22, 16, 10, 16, 12, 18, 28, 20, 14, 22, 16, 2, 4, 4, 6, 10, 8, 6, 10, 8, 10, 16, 12, 18, 28, 20, 14, 22, 16, 10, 16, 12, 18, 28, 20, 14, 22, 16, 18, 28, 20, 30
OFFSET
0,2
COMMENTS
Two integers can be added without carries in balanced ternary if they have no equal nonzero digit at the same position.
This sequence has connections with Gould's sequence (A001316); here we work with balanced ternary, there with binary.
LINKS
FORMULA
a(n) <= n+1 with equality iff n belongs to A140429.
a(3*n) = 3*a(n) - 2.
a(3*n+1) = a(3*n-1) + 2.
EXAMPLE
For n = 8:
- we consider the following cases:
k| 0 1 2 3 4 5 6 7 8
---------+---------------------------------------------
bter(k)| 0 1 1T 10 11 1TT 1T0 1T1 10T
bter(8-k)| 10T 1T1 1T0 1TT 11 10 1T 1 0
carries?| no yes no no yes no no yes no
- so a(8) = 6.
PROG
(PARI) ok(u, v) = { while (u && v, my (uu=[0, +1, -1][1+u%3], vv=[0, +1, -1][1+v%3]); if (abs(uu+vv)>1, return (0)); u=(u-uu)/3; v=(v-vv)/3); return (1) }
a(n) = sum(k=0, n, ok(n-k, k))
CROSSREFS
Cf. A001316, A059095, A140429, A353174 (corresponding k's).
Sequence in context: A368558 A060267 A214516 * A238004 A048244 A056673
KEYWORD
nonn,base
AUTHOR
Rémy Sigrist, Apr 28 2022
STATUS
approved