OFFSET
1,1
LINKS
Jud McCranie, Table of n, a(n) for n = 1..40
J. C. Lagarias, The 3x+1 problem and its generalizations, Amer. Math. Monthly, 92 (1985), 3-23.
Carlos Rivera, Puzzle 634. Primes in Collatz trajectory
Carlos Rivera, Puzzle 922. Follow up to Puzzle 634
EXAMPLE
The sequence n, f(n), f(f(n)), ..., 1 for n = 7 is: 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1, which has six prime terms, more prime terms than for any n < 7. Hence 7 sets a record and so belongs to the sequence.
MATHEMATICA
f[n_] := n/2 /; Mod[n, 2] == 0 f[n_] := 3 n + 1 /; Mod[n, 2] == 1 g[n_] := Module[{i, p}, i = n; p = 0; While[i > 1, If[PrimeQ[i], p = p + 1]; i = f[i]]; p]; high = 0; a = {}; For[j = 1, j <= 10^5, j++, k = g[j]; If[k > high, high = k; a = Append[a, j]]]; a
(* Second program: *)
With[{s = Array[Count[NestWhileList[If[EvenQ[#], #/2, 3 # + 1] &, #, # > 1 &], _?PrimeQ] &, 10^5]}, Map[FirstPosition[s, #][[1]] &, Union@ FoldList[Max, s]]] (* Michael De Vlieger, Apr 21 2018 *)
PROG
(PARI) A078350(n)=my(s=isprime(n)); while(n>1, if(n%2, n=(3*n+1)/2, n/=2); s+=isprime(n)); s
r=0; for(n=2, 1e9, t=A078350(n); if(t>r, r=t; print1(n", "))) \\ Charles R Greathouse IV, Apr 28 2015
CROSSREFS
KEYWORD
nonn
AUTHOR
Joseph L. Pe, Dec 24 2002
EXTENSIONS
a(18)-a(30) from Donovan Johnson, Jul 02 2010
a(31)-a(33) from Carlos Rivera, Apr 15 2012
STATUS
approved