%I #41 Jan 08 2021 14:02:19
%S 5,15,50,150,455,1365,4100,12300,36905,110715,332150,996450,2989355,
%T 8968065,26904200,80712600,242137805,726413415,2179240250,6537720750,
%U 19613162255,58839486765,176518460300,529555380900,1588666142705,4765998428115,14297995284350
%N a(n) = A340131(A001006(n)).
%C This sequence is associated with A340131, whose terms are sorted by the length of their ternary code. Elements with the same length of ternary code form a range that has a maximum. The maximal term of the n-range (a set of elements with ternary code length n in A340131) is a(n). Example: numbers 29, 33, 44, 45 and 50 have a ternary length of 4 (see A340131), respectively a(4) = 50.
%C Ternary code for a(n) is 12..12 for even n and 12..120 for odd n.
%H Andrew Howroyd, <a href="/A340395/b340395.txt">Table of n, a(n) for n = 2..1000</a>
%H Gennady Eremin, <a href="https://arxiv.org/abs/2012.12675">Arithmetization of well-formed parenthesis strings. Motzkin Numbers of the Second Kind</a>, arXiv:2012.12675 [math.CO], 2020.
%H <a href="/index/Rec#order_03">Index entries for linear recurrences with constant coefficients</a>, signature (3,1,-3).
%F a(n) = 5*3^(n-2*k)*(9^k-1)/8 where k = floor(n/2).
%F a(n+1) = 3*a(n) for even n >= 2; a(n+1) = 3*a(n)+5 for odd n >= 3.
%F a(n) = 5*A033113(n-1).
%F a(n) = (5/8)*(3^n - (-1)^(n-1) - 2).
%F a(n) = 2*a(n-1) + 3*a(n-2) + 5 for n > 3.
%F From _Stefano Spezia_, Jan 06 2021: (Start)
%F G.f.: 5*x^2/(1 - 3*x - x^2 + 3*x^3).
%F a(n) = 3*a(n-1) + a(n-2) - 3*a(n-3) for n > 4. (End)
%e A001006(2) = 2, so a(2) = A340131(2) = 5.
%e A001006(3) = 4, so a(3) = A340131(4) = 15, etc.
%o (PARI) Vec(5/(1 - 3*x - x^2 + 3*x^3) + O(x^30)) \\ _Andrew Howroyd_, Jan 08 2021
%Y Subsequence of A340131.
%K nonn,easy,base
%O 2,1
%A _Gennady Eremin_, Jan 06 2021