OFFSET
0,1
COMMENTS
Also known as the Collatz sequence. - Harvey P. Dale, Feb 03 2026
REFERENCES
R. K. Guy, Unsolved Problems in Number Theory, E16.
LINKS
FORMULA
G.f.: (87 + 262*x + 131*x^2 + 307*x^3 - 65*x^4 + 461*x^5 - 98*x^6 - 49*x^7 - 518*x^8 - 259*x^9 - 36*x^10 - 18*x^11 - 9*x^12 - 98*x^13 - 49*x^14 - 6*x^15 - 3*x^16 + 27*x^17 - 5*x^18 + 41*x^19 - 8*x^20 - 4*x^21 - 12*x^22 - 6*x^23 - 3*x^24 - 35*x^25 - 4*x^26 - 2*x^27 - x^28 - 14*x^29 - 7*x^30)/(1 - x^3). - Charles R Greathouse IV, May 17 2026
MAPLE
f := proc(n) option remember; if n = 0 then 87; elif f(n-1) mod 2 = 0 then f(n-1)/2 else 3*f(n-1)+1; fi; end;
MATHEMATICA
NestList[If[EvenQ[#], #/2, 3# + 1]&, 87, 100] (* Vincenzo Librandi, Jul 29 2014 *)
PROG
(Magma) [n eq 1 select 87 else IsOdd(Self(n-1)) select 3*Self(n-1)+1 else Self(n-1) div 2: n in [1..80]]; // Vincenzo Librandi, Jul 29 2014
(PARI) a(n)=if(n>27, [1, 4, 2][n%3+1], [87, 262, 131, 394, 197, 592, 296, 148, 74, 37, 112, 56, 28, 14, 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8][n+1]) \\ Charles R Greathouse IV, May 17 2026
(PARI) a(n)=if(n>27, ([0, 1, 0; 0, 0, 1; 1, 0, 0]^(n-28)*[4; 2; 1])[1, 1], [87, 262, 131, 394, 197, 592, 296, 148, 74, 37, 112, 56, 28, 14, 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8][n+1]) \\ Charles R Greathouse IV, May 26 2026
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
STATUS
approved
