OFFSET
0,3
COMMENTS
As shown in the proof of [Gruber and Holzer, lemma 9], the maximum is attained by choosing i as the largest number not exceeding n whose ternary representation is (22...2)_3. By [Gruber and Holzer, lemma 6], for this choice of i we have S_3(i) = 2*floor(log_3(n+1)) and S_3(n-i) = S_3(n+1)-1, giving the formula below.
REFERENCES
Hermann Gruber and Markus Holzer, Optimal Regular Expressions for Palindromes of Given Length. Extended journal version, in preparation, 2024.
LINKS
Paolo Xausa, Table of n, a(n) for n = 0..10000
Hermann Gruber and Markus Holzer, Optimal Regular Expressions for Palindromes of Given Length, Proceedings of the 46th International Symposium on Mathematical Foundations of Computer Science, Article No. 53, pp. 53:1-53:15, 2021.
FORMULA
a(n) = 2*floor(log_3(n+1)) + A053735(n+1) - 1 [Gruber and Holzer, lemma 9].
EXAMPLE
For n=31, the maximum is attained by 26 + 5 = (222)_3 + (12)_3. Using 32=(1021)_3, comparing with the formula above, S_3(26) = 2*floor(log_3(n+1)) = 6 and S_3(5) = S_3(31+1)-1 = 3. Notice that other pairs attain the maximum as well, namely 23 + 8 = (22)_3 + (212)_3, as well as 20 + 11 = (202)_3 + (102)_3.
MAPLE
f:= n -> 2 * ilog[3](n+1) + convert(convert(n+1, base, 3), `+`) - 1:
map(f, [$0..100]); # Robert Israel, Jun 27 2024
MATHEMATICA
Table[2*Floor[Log[3, k]] + DigitSum[k, 3] - 1, {k, 100}] (* Paolo Xausa, Aug 01 2024 *)
PROG
(PARI) a(n) = 2*logint(n+1, 3) + sumdigits(n+1, 3) - 1; \\ Michel Marcus, Jul 05 2024
CROSSREFS
KEYWORD
nonn,easy,base
AUTHOR
Hermann Gruber, Jun 26 2024
STATUS
approved