cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

Showing 1-2 of 2 results.

A078350 Number of primes in {n, f(n), f(f(n)), ..., 1}, where f is the Collatz function defined by f(x) = x/2 if x is even; f(x) = 3x + 1 if x is odd.

Original entry on oeis.org

0, 1, 3, 1, 2, 3, 6, 1, 6, 2, 5, 3, 3, 6, 4, 1, 4, 6, 7, 2, 1, 5, 4, 3, 7, 3, 25, 6, 6, 4, 24, 1, 7, 4, 3, 6, 7, 7, 11, 2, 25, 1, 8, 5, 4, 4, 23, 3, 7, 7, 6, 3, 3, 25, 24, 6, 8, 6, 11, 4, 5, 24, 20, 1, 7, 7, 9, 4, 3, 3, 22, 6, 25, 7, 2, 7, 6, 11, 11, 2, 5, 25, 24, 1, 1, 8, 9, 5, 10, 4, 20, 4, 3, 23, 20
Offset: 1

Views

Author

Joseph L. Pe, Dec 23 2002

Keywords

Comments

Number of primes in the trajectory of n under the 3x+1 map (i.e., the number of primes until the trajectory reaches 1, including 2 once). - Benoit Cloitre, Dec 23 2002
a(A196871(n)) = 0. - Reinhard Zumkeller, Oct 08 2011
a(A181921(n)) = n and a(m) <> n for m < A181921(n). - Reinhard Zumkeller, Apr 03 2012

Examples

			3 -> 10 -> 5 -> 16 -> 8 -> 4 -> 2 -> 1; in this trajectory 3, 5, 2 are primes hence a(3) = 3. - _Benoit Cloitre_, Dec 23 2002
The finite sequence n, f(n), f(f(n)), ..., 1 for n = 12 is 12, 6, 3, 10, 5, 16, 8, 4, 2, 1, which has three prime terms. Hence a(12) = 3.
		

Crossrefs

Programs

  • Haskell
    a078350 n = sum $ map a010051 $ takeWhile (> 1) $ iterate a006370 n  -- Reinhard Zumkeller, Oct 08 2011
  • Maple
    a:= proc(n) option remember; `if`(n=1, 0,
         `if`(isprime(n), 1, 0)+a(`if`(n::even, n/2, 3*n+1)))
        end:
    seq(a(n), n=1..100);  # Alois P. Heinz, Nov 04 2024
  • 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]; Table[g[n], {n, 1, 100}]
    Table[Count[NestWhileList[If[EvenQ[#],#/2,3#+1]&,n,#!=1&],?PrimeQ],{n,100}] (* _Harvey P. Dale, Aug 29 2012 *)
  • PARI
    for(n=2,500,s=n; t=0; while(s!=1,if(isprime(s)==1,t=t+1,t=t); if(s%2==0,s=s/2,s=(3*s+1)); if(s==1,print1(t,","); ); )) \\ Benoit Cloitre, Dec 23 2002
    
  • PARI
    a(n)=my(s=isprime(n));while(n>1,if(n%2,n=(3*n+1)/2,n/=2);s+=isprime(n));s \\ Charles R Greathouse IV, Apr 28 2015
    
  • PARI
    A078350(n,c=n>1)={while(1>=valuation(n,2), isprime(n)&&c++; n=n*3+1);c} \\ M. F. Hasler, Dec 05 2017
    

Formula

a(n) = A055509(n) + 1 for n > 1.
a(n) = 1 when n > 1 is in A000079, i.e., a power of 2. - Benoit Cloitre, Dec 20 2017

Extensions

Edited by N. J. A. Sloane, Jan 17 2009 at the suggestion of R. J. Mathar

A064685 Length of orbit of 2n+1 in the 3x+1 problem.

Original entry on oeis.org

1, 8, 6, 17, 20, 15, 10, 18, 13, 21, 8, 16, 24, 112, 19, 107, 27, 14, 22, 35, 110, 30, 17, 105, 25, 25, 12, 113, 33, 33, 20, 108, 28, 28, 15, 103, 116, 15, 23, 36, 23, 111, 10, 31, 31, 93, 18, 106, 119, 26, 26, 88, 39, 101, 114, 70, 13, 34, 21, 34, 96, 47, 109, 47, 122
Offset: 0

Views

Author

Jon Perry, Oct 10 2001

Keywords

Examples

			E.g. orbit(3) = 3->10->5->16->8->4->2->1, so length of chain = 8. So a(1) = 8.
		

Programs

  • ARIBAS
    function a064685(maxarg: integer); var n: integer; begin for n := 1 to maxarg by 2 do write(length(orbit(n))," "); end; end; a064685(140); (* For definition of function orbit see A064684. *)

Formula

f(n)= n/2 if n is even, 3n+1 if n is odd; stop if n is 1.

Extensions

More terms from Klaus Brockhaus, Oct 13 2001
Showing 1-2 of 2 results.