%I #138 Jun 27 2024 03:51:36
%S 1,1,2,1,1,2,1,1,3,1,1,2,1,1,2,1,1,3,1,1,2,1,1,2,1,1,4,1,1,2,1,1,2,1,
%T 1,3,1,1,2,1,1,2,1,1,3,1,1,2,1,1,2,1,1,4,1,1,2,1,1,2,1,1,3,1,1,2,1,1,
%U 2,1,1,3,1,1,2,1,1,2,1,1,5,1,1,2,1,1,2,1,1,3,1,1,2,1,1,2,1,1,3,1,1,2,1,1,2
%N 3^a(n) exactly divides 3n. Or, 3-adic valuation of 3n.
%C a(n) is the Hamming distance between n and n-1 in ternary representation. - _Philippe Deléham_, Mar 29 2004
%C 3^a(n) divides 4^n-1. - _Benoit Cloitre_, Oct 25 2004
%C Generalized Ruler Function for k=3. - _Frank Ruskey_ and Chris Deugau (deugaucj(AT)uvic.ca)
%C a(A007417(n)) is odd and a(A145204(n)) is even. - _Reinhard Zumkeller_, May 23 2013
%C First n terms comprise least cubefree word of length n using positive integers, where "cubefree" means that the word contains no three consecutive identical subwords; e.g., 1 contains no cube; 11 contains no cube; 111 does but 112 does not; ... 1,1,2,1,1,2,1,1,1 does, and 1,1,2,1,1,2,1,1,2 does, but 1,1,2,1,1,2,1,1,3 does not, etc. - _Clark Kimberling_, Sep 10 2013
%C The sequence is invariant under the "lower trim" operator: remove all ones, and subtract one from each remaining term. - _Franklin T. Adams-Watters_, May 25 2017
%C a(n) is the dimension in which the coordinates of the vertices n-1 and n differ in the ternary reflected Gray code. - _Arie Bos_, Jul 12 2023
%D Letter from Gary W. Adamson to N. J. A. Sloane concerning Prouhet-Thue-Morse sequence, Nov. 11, 1999.
%H Amiram Eldar, <a href="/A051064/b051064.txt">Table of n, a(n) for n = 1..10000</a> (terms 1..1000 from T. D. Noe)
%H A. M. Hinz, S. Klavžar, U. Milutinović, and C. Petr, <a href="http://dx.doi.org/10.1007/978-3-0348-0237-6">The Tower of Hanoi - Myths and Maths</a>, Birkhäuser 2013. See page 243. <a href="http://tohbook.info">Book's website</a>
%H Simon Plouffe, <a href="https://arxiv.org/abs/1310.7195">On the values of the functions zeta and gamma</a>, arXiv preprint arXiv:1310.7195 [math.NT], 2013.
%H Joseph Rosenbaum, <a href="https://doi.org/10.2307/2302451">Elementary Problem E319</a>, American Mathematical Monthly, volume 45, number 10, December 1938, pages 694-696. (The A indices in P at equations 1' and 2' for p=3.)
%H <a href="/index/Fi#FIXEDPOINTS">Index entries for sequences that are fixed points of mappings</a>
%F a(n) = A007949(n) + 1 = A004128(n) - A004128(n-1).
%F Multiplicative with a(p^e) = e+1 if p = 3; 1 if p <> 3. - _Vladeta Jovovic_, Aug 24 2002
%F G.f.: Sum_{k>=0} x^3^k/(1-x^3^k). - _Ralf Stephan_, Apr 12 2002
%F Fixed point of the morphism: 1 -> 112; 2 -> 113; 3 -> 114; 4 -> 115; ...; starting from a(1) = 1. a(3n+1) = a(3n+2) = 1; a(3n) = 1 + a(n). - _Philippe Deléham_, Mar 29 2004
%F a(n) = (-1)*Sum_{d divides n} mu(3d)*tau(n/d). - _Benoit Cloitre_, Jun 21 2007
%F Dirichlet g.f.: zeta(s)/(1-1/3^s). - _R. J. Mathar_, Jun 13 2011
%F a(n) = (1/2)*(3 - A053735(n) + A053735(n-1)) for n >= 1. - _Tom Edgar_, Aug 06 2014
%F a(n) = A007949(3n). - _Cyril Damamme_, Aug 04 2015
%F a(2n) = a(n), a(2n-1) = A254046(n). - _Cyril Damamme_, Aug 04 2015
%F G.f. A(x) satisfies: A(x) = A(x^3) + x/(1 - x). - _Ilya Gutkovskiy_, May 03 2019
%F Asymptotic mean: lim_{m->oo} (1/m) * Sum_{k=1..m} a(k) = 3/2. - _Amiram Eldar_, Sep 11 2020 [corrected by _Vaclav Kotesovec_, Jun 25 2024, see also A004128]
%F a(n) = tau(n)/(tau(3*n) - tau(n)), where tau(n) = A000005(n). - _Peter Bala_, Jan 06 2021
%e 3^2 | 3*6 = 18, so a(6) = 2.
%p seq(1+padic:-ordp(n,3), n=1..100); # _Robert Israel_, Aug 07 2014
%t Nest[ Function[ l, {Flatten[(l /. {1 -> {1, 1, 2}, 2 -> {1, 1, 3}, 3 -> {1, 1, 4}, 4 -> {1, 1, 5}})]}], {1}, 5] (* _Robert G. Wilson v_, Mar 03 2005 *)
%t Table[ IntegerExponent[3n, 3], {n, 1, 105}] (* _Jean-François Alcover_, Oct 10 2011 *)
%o (PARI) a(n)=if(n<1,0,1+valuation(n,3))
%o (Haskell)
%o a051064 = (+ 1) . length .
%o takeWhile (== 3) . dropWhile (== 2) . a027746_row
%o -- _Reinhard Zumkeller_, May 23 2013
%o (Python)
%o def A051064(n):
%o c = 1
%o a, b = divmod(n,3)
%o while b == 0:
%o a, b = divmod(a,3)
%o c += 1
%o return c # _Chai Wah Wu_, Apr 18 2022
%Y Cf. A001511, A007949.
%Y Partial sums give A004128.
%Y Cf. A000005, A027746.
%Y Cf. A254046.
%K nonn,easy,nice,mult
%O 1,3
%A _N. J. A. Sloane_, _Gary W. Adamson_
%E More terms from _James A. Sellers_, Dec 11 1999
%E More terms from _Vladeta Jovovic_, Aug 24 2002