A135282 Largest k such that 2^k appears in the trajectory of the Collatz 3x+1 sequence started at n.
0, 1, 4, 2, 4, 4, 4, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 4, 4, 4, 4, 4, 4, 4, 4, 6, 8, 4, 4
Offset: 1
Keywords
Examples
a(6) = 4 because the sequence is 6, 3, 10, 5, 16, 8, 4, 2, 1; there 16 = 2^4 is the largest power of 2 encountered.
Links
Programs
-
C
#include
int main(){ int i, s, f; for(i = 2; i < 10000; i++){ f = 0; s = i; while(s != 1){ if(s % 2 == 0){ s = s/2; f++;} else{ f = 0; s = 3 * s + 1; } } printf("%d,", f); } return 0; } /* Masahiko Shin, Mar 16 2010 */ -
Haskell
a135282 = a007814 . head . filter ((== 1) . a209229) . a070165_row -- Reinhard Zumkeller, Jan 02 2013
-
Maple
A135282 := proc(n) local k,threen1 ; k := 0 : threen1 := n ; while threen1 > 1 do if 2^ilog[2](threen1) = threen1 then k := max(k,ilog[2](threen1)) ; fi ; if threen1 mod 2 = 0 then threen1 := threen1/2 ; else threen1 := 3*threen1+1 ; fi ; od: RETURN(k) ; end: for n from 1 to 80 do printf("%d, ",A135282(n)) ; od: # R. J. Mathar, Dec 12 2007
-
Mathematica
Collatz[n_] := If[EvenQ[n], n/2, 3*n + 1]; Log[2, Table[NestWhile[Collatz, n, ! IntegerQ[Log[2, #]] &], {n, 100}]] (* T. D. Noe, Mar 05 2012 *)
Formula
a(n) = A006577(n) - A208981(n) (after Alonso del Arte's comment in A208981), if A006577(n) is not -1. - Omar E. Pol, Apr 10 2022
Extensions
Edited and extended by R. J. Mathar, Dec 12 2007
More terms from Masahiko Shin, Mar 16 2010
Comments