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-4 of 4 results.

A339991 The number of steps that n requires to reach 1 under the map: m -> m/2 if m is even, m-> m^2 - 1 if m is an odd prime, otherwise m -> m - 1. a(n) = -1 if 1 is never reached.

Original entry on oeis.org

0, 1, 4, 2, 8, 5, 9, 3, 4, 9, 15, 6, 15, 10, 11, 4, 10, 5, 22, 10, 11, 16, 11, 7, 8, 16, 17, 11, 23, 12, 18, 5, 6, 11, 12, 6, 20, 23, 24, 11, 24, 12, 21, 17, 18, 12, 19, 8, 9, 9, 10, 17, 31, 18, 19, 12, 13, 24, 27, 13, 32, 19, 20, 6, 7, 7, 21, 12, 13, 13, 27
Offset: 1

Views

Author

Ya-Ping Lu, Dec 25 2020

Keywords

Comments

Conjecture: a(n) is never equal to -1.
An even node (m) in the tree shown in Example can have up to three predecessors: 2*m, sqrt(m+1) if sqrt(m+1) is a prime, and m+1 if m+1 is a nonprime odd number. An odd node has only one predecessor: 2*m.

Examples

			The 39 starting numbers with a(n) <= 9 are given in the figure below.
10 50 7 49 96 145 288 133 264 260 258 512
  \  \ \ | /   \  /    \ /    /   /   /
   5 25 48     144     132  130  129 256
    \ | /        \       \    \   \ /
     24          72      66  65  128
       \          \       \   \  /
        12        36      33   64
          \        \       \  /
           6       18       32
             \      \      /
               3    9   16
                  \ | /
                    8
                    |
                    4
                    |
                    2
                    |
                    1
		

Crossrefs

Programs

  • Maple
    A339991 := proc(n)
        local a,x;
        x := n ;
        a := 0 ;
        while x > 1 do
            if type(x,even) then
                x := x/2 ;
            elif isprime(x) then
                x := x^2-1 ;
            else
                x := x-1 ;
            end if ;
            a := a+1 ;
        end do:
        a ;
    end proc:
    seq(A339991(n),n=1..50) ; # R. J. Mathar, Jun 27 2024
  • Mathematica
    Array[-1 + Length@ NestWhileList[Which[EvenQ@ #, #/2, PrimeQ@ #, #^2 - 1, True, # - 1] &, #, # > 1 &] &, 71] (* Michael De Vlieger, Dec 28 2020 *)
  • PARI
    f(n) = if (n%2, if (isprime(n), n^2-1, n-1), n/2);
    a(n) = my(nb=0); while (n != 1, n = f(n); nb++); nb; \\ Michel Marcus, Dec 26 2020
  • Python
    from sympy import isprime
    for n in range(1, 1001):
        ct, m = 0, n
        while m > 1:
            if m%2 == 0: m //= 2
            elif isprime(m) == 1: m = m*m - 1
            else: m -= 1
            ct += 1
        print(ct)
    

A346063 a(n) = primepi(A039634(prime(n)^2-1)).

Original entry on oeis.org

2, 1, 2, 2, 4, 3, 1, 5, 1, 6, 4, 3, 6, 4, 7, 14, 6, 10, 7, 37, 23, 25, 28, 18, 21, 22, 67, 24, 9, 46, 11, 19, 62, 12, 40, 24, 2, 27, 6, 91, 11, 31, 20, 1, 36, 203, 69, 25, 2, 80, 16, 48, 155, 18, 1, 326, 7, 20, 109, 365, 8, 39, 9, 240, 438, 2, 16, 154, 10, 17
Offset: 1

Views

Author

Ya-Ping Lu, Jul 03 2021

Keywords

Comments

This sequence looks at the effect on p^2 - 1 of A039634 with the primes represented by their indices. It seems that primes obtained by iterating the map A039634 on p^2 - 1 never fall into a cycle before reaching 2. Conjecture: Iterating the map k -> a(k) eventually reaches 1. For example, 1 -> 2 -> 1; 5 -> 4 -> 2 -> 1; and 27 -> 67 -> 16 -> 14 -> 4 -> 2 -> 1.
If the conjecture holds, then A339991(n) != -1 and A340419 is a finite sequence.

Crossrefs

Programs

  • Mathematica
    Array[PrimePi@ FixedPoint[If[EvenQ[#] && # > 2, #/2, If[PrimeQ[#] || (# === 1), #, (# - 1)/2]] &, Prime[#]^2 - 1] &, 70] (* Michael De Vlieger, Jul 06 2021 *)
  • Python
    from sympy import prime, isprime, primepi
    def a(n):
        p = prime(n); m = p*p - 1
        while not isprime(m): m = m//2
        return primepi(m)
    for n in range(1, 71): print(a(n))

Formula

a(n) = A000720(A039634(A000040(n)^2-1)). - Pontus von Brömssen, Jul 03 2021

A340420 The number of steps that n requires to reach 1 under the map: m -> m/2 if m is even, m-> 3*m + 1 if m is an odd prime, otherwise m -> m - 1. a(n) = -1 if 1 is never reached.

Original entry on oeis.org

0, 1, 7, 2, 5, 8, 16, 3, 4, 6, 14, 9, 9, 17, 18, 4, 12, 5, 20, 7, 8, 15, 16, 10, 11, 10, 11, 18, 18, 19, 19, 5, 6, 13, 14, 6, 21, 21, 22, 8, 22, 9, 9, 16, 17, 17, 17, 11, 12, 12, 13, 11, 11, 12, 13, 19, 20, 19, 32, 20, 20, 20, 21, 6, 7, 7, 27, 14, 15, 15, 15
Offset: 1

Views

Author

Ya-Ping Lu, Jan 07 2021

Keywords

Comments

Conjecture: a(n) is never equal to -1.

Examples

			a(3) = 7 because 3*3 + 1 = 10 -> 10/2 = 5 -> 3*5 + 1 = 16 -> 16/2 = 8 -> 8/2 = 4 -> 4/2 = 2 -> 2/2 = 1 -> 1.
a(14) = 17 because 14 -> 7 -> 22 -> 11 -> 34 -> 17 -> 52 -> 26 -> 13 -> 40 -> 20 -> 10 -> 5 -> 16 -> 8 -> 4 -> 2 -> 1.
The 39 terms for a(n) <= 9 are given in the figure below.
145 288 12 42 13 80 133 264 260 258 255 512
  \  /   \  \  \ /    \ /    |   |   \  /
   144    6  21 40    132   130 129  256
     \     \   \ |     |     |    \  /
      72    3   20     66    65   128
        \     \ /       \     \   /
         36    10       33      64
           \     \        \    /
            18     5        32
               \     \     /
                 9      16
                   \    /
                      8
                      |
                      4
                      |
                      2
                      |
                      1
		

Crossrefs

Programs

  • Maple
    a:= proc(n) option remember; `if`(n=1, 0, 1 + a(
         `if`(n::even, n/2, `if`(isprime(n), 3*n+1, n-1))))
        end:
    seq(a(n), n=1..100);  # Alois P. Heinz, Jan 08 2021
  • Mathematica
    a[n_] := a[n] = If[n == 1, 0, 1 + a[
       If[EvenQ[n], n/2, If[PrimeQ[n], 3n+1, n-1]]]];
    Array[a, 100] (* Jean-François Alcover, Jan 30 2021, after Alois P. Heinz *)
  • PARI
    f(n) = if (n % 2, if (isprime(n), 3*n+1, n-1), n/2);
    a(n) = my(s=n, c=0); while(s>1, s=f(s); c++); c; \\ Michel Marcus, Jan 21 2021
  • Python
    from sympy import isprime
    for n in range(1, 101):
        ct, m = 0, n
        while m > 1:
            if m%2 == 0: m //= 2
            elif isprime(m) == 1: m = 3*m + 1
            else: m -= 1
            ct += 1
        print(ct)
    

A346136 a(n) is the number of iterations that n requires to reach 1 under the map n -> A346063(n).

Original entry on oeis.org

0, 1, 2, 2, 3, 3, 1, 4, 1, 4, 3, 3, 4, 3, 2, 4, 4, 5, 2, 3, 9, 11, 8, 6, 10, 12, 6, 7, 2, 8, 4, 3, 6, 4, 10, 7, 2, 7, 4, 9, 4, 5, 4, 1, 8, 7, 6, 11, 2, 73, 5, 12, 5, 6, 1, 5, 2, 4, 34, 7, 5, 5, 2, 51, 7, 2, 5, 3, 5, 5, 3, 15, 6, 5, 2, 4, 10
Offset: 1

Views

Author

Ya-Ping Lu, Jul 05 2021

Keywords

Comments

Conjecture: the sequence is infinite.

Crossrefs

Programs

  • PARI
    f(x) = my(k=x^2-1); while(k>3 && !ispseudoprime(k), k\=2); k;
    a(n) = my(c=0, x=prime(n)); while(x>2, c++; x=f(x)); c; \\ Jinyuan Wang, Jul 15 2022
  • Python
    from sympy import prime, isprime
    for n in range(1, 78):
        m = prime(n); ct = 0
        while m > 2:
            if isprime(m): m = m*m - 1; ct += 1
            else: m //= 2
        print(ct)
    

Extensions

a(1) corrected by Jinyuan Wang, Jul 15 2022
Showing 1-4 of 4 results.