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.
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
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
Links
- Alois P. Heinz, Table of n, a(n) for n = 1..65536
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)
Comments