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.

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.

This page as a plain text file.
%I A340420 #20 Jun 17 2025 20:21:16
%S A340420 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,
%T A340420 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,
%U A340420 12,13,19,20,19,32,20,20,20,21,6,7,7,27,14,15,15,15
%N 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.
%C A340420 Conjecture: a(n) is never equal to -1.
%H A340420 Alois P. Heinz, <a href="/A340420/b340420.txt">Table of n, a(n) for n = 1..65536</a>
%e A340420 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.
%e A340420 a(14) = 17 because 14 -> 7 -> 22 -> 11 -> 34 -> 17 -> 52 -> 26 -> 13 -> 40 -> 20 -> 10 -> 5 -> 16 -> 8 -> 4 -> 2 -> 1.
%e A340420 The 39 terms for a(n) <= 9 are given in the figure below.
%e A340420 145 288 12 42 13 80 133 264 260 258 255 512
%e A340420   \  /   \  \  \ /    \ /    |   |   \  /
%e A340420    144    6  21 40    132   130 129  256
%e A340420      \     \   \ |     |     |    \  /
%e A340420       72    3   20     66    65   128
%e A340420         \     \ /       \     \   /
%e A340420          36    10       33      64
%e A340420            \     \        \    /
%e A340420             18     5        32
%e A340420                \     \     /
%e A340420                  9      16
%e A340420                    \    /
%e A340420                       8
%e A340420                       |
%e A340420                       4
%e A340420                       |
%e A340420                       2
%e A340420                       |
%e A340420                       1
%p A340420 a:= proc(n) option remember; `if`(n=1, 0, 1 + a(
%p A340420      `if`(n::even, n/2, `if`(isprime(n), 3*n+1, n-1))))
%p A340420     end:
%p A340420 seq(a(n), n=1..100);  # _Alois P. Heinz_, Jan 08 2021
%t A340420 a[n_] := a[n] = If[n == 1, 0, 1 + a[
%t A340420    If[EvenQ[n], n/2, If[PrimeQ[n], 3n+1, n-1]]]];
%t A340420 Array[a, 100] (* _Jean-François Alcover_, Jan 30 2021, after _Alois P. Heinz_ *)
%o A340420 (Python)
%o A340420 from sympy import isprime
%o A340420 for n in range(1, 101):
%o A340420     ct, m = 0, n
%o A340420     while m > 1:
%o A340420         if m%2 == 0: m //= 2
%o A340420         elif isprime(m) == 1: m = 3*m + 1
%o A340420         else: m -= 1
%o A340420         ct += 1
%o A340420     print(ct)
%o A340420 (PARI) f(n) = if (n % 2, if (isprime(n), 3*n+1, n-1), n/2);
%o A340420 a(n) = my(s=n, c=0); while(s>1, s=f(s); c++); c; \\ _Michel Marcus_, Jan 21 2021
%Y A340420 Cf. A006577, A060413, A339991, A340008, A340418.
%K A340420 nonn,look
%O A340420 1,3
%A A340420 _Ya-Ping Lu_, Jan 07 2021