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.
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
Examples
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.
Links
- Antti Karttunen, Table of n, a(n) for n = 0..16384
- Eric Weisstein's World of Mathematics, Ternary
Programs
-
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 *)
-
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
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
Comments