OFFSET
1,3
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.
EXAMPLE
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
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 *)
PROG
(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)
(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
CROSSREFS
KEYWORD
nonn
AUTHOR
Ya-Ping Lu, Dec 25 2020
STATUS
approved