login
A117971
One-based position of the first 2 from the least significant digit in the ternary expansion of 2^n, or 0 if there are no 2's present.
3
0, 1, 0, 1, 2, 1, 4, 1, 0, 1, 2, 1, 3, 1, 3, 1, 2, 1, 5, 1, 8, 1, 2, 1, 11, 1, 11, 1, 2, 1, 3, 1, 3, 1, 2, 1, 4, 1, 4, 1, 2, 1, 5, 1, 4, 1, 2, 1, 3, 1, 3, 1, 2, 1, 6, 1, 8, 1, 2, 1, 4, 1, 7, 1, 2, 1, 3, 1, 3, 1, 2, 1, 12, 1, 7, 1, 2, 1, 6, 1, 10, 1, 2, 1, 3, 1, 3, 1, 2, 1, 4, 1, 4, 1, 2, 1, 6, 1, 4, 1, 2, 1, 3, 1
OFFSET
0,5
COMMENTS
a(0), a(2) and a(8) are the conjectured to be the only terms equal to 0.
LINKS
Eric Weisstein's World of Mathematics, Ternary
EXAMPLE
For n=0, 2^0 = 1 is also "1" in base-3, thus there are no 2-digits present, and therefore a(0) = 0.
For n=4, 2^4 = 16, which in base-3 is "121" as 1*(3^2) + 2*3 + 1 = 16, so the rightmost 2 occurs at two steps from the end, therefore a(4) = 2.
For n=5, 2^5 = 32, which in base-3 is "1012" as 1*(3^3) + 1*3 + 2*1 = 32, so the rightmost 2 occurs as the least significant digit (which is the position 1), therefore a(5) = 1.
MATHEMATICA
pf2[n_]:=Module[{p=Position[Reverse[IntegerDigits[2^n, 3]], 2, {1}, 1]}, If[p=={}, 0, p]]; Flatten[Array[pf2, 110]] (* Harvey P. Dale, Nov 30 2013 *)
PROG
(PARI) A117971(n) = { my(n=(2^n), i=1); while(n, if(2==(n%3), return(i)); i++; n \= 3); (0); }; \\ Antti Karttunen, Mar 30 2021
CROSSREFS
Cf. A004642 (ternary expansion of 2^n), A007089. See also A117970.
Sequence in context: A140505 A295881 A371890 * A353606 A220420 A190616
KEYWORD
nonn,base
AUTHOR
Eric W. Weisstein, Apr 06 2006
EXTENSIONS
Edited by Charles R Greathouse IV, Aug 05 2010
Term a(0) = 0 prepended, examples added and the definition clarified by Antti Karttunen, Mar 30 2021
STATUS
approved