A385613 Number of steps that n requires to reach 0 under the map: x-> x^2 - 1 if x is an odd prime, floor(x/3) if x is even, otherwise x - 1. a(n) = -1 if 0 is never reached.
0, 1, 1, 3, 2, 4, 2, 7, 2, 3, 4, 9, 3, 6, 3, 4, 5, 8, 3, 10, 3, 4, 8, 14, 3, 4, 3, 4, 4, 10, 5, 15, 5, 6, 10, 11, 4, 10, 4, 5, 7, 8, 4, 14, 4, 5, 5, 10, 6, 7, 6, 7, 9, 15, 4, 5, 4, 5, 11, 9, 4, 18, 4, 5, 5, 6, 9, 10, 9, 10, 15, 9, 4, 22, 4, 5, 5, 6, 4, 11, 4
Offset: 0
Keywords
Examples
a(5) = 4 because iterating the map on n = 5 results in 0 in 4 steps: 5 -> 5^2-1=24 -> floor(24/3)=8 -> floor(8/3)=2 -> floor(2/3)=0. a(9949031) = -1 because iterating the map on n = 9949031 ends up in the 33-member loop in 5 steps: 9949031 -> 9949030 -> 3316343 -> 3316342 -> 1105447 -> 1105446.
Programs
-
Python
from sympy import isprime def A385613(n): S = {n} while n != 0: n = n//3 if n%2 == 0 else n*n - 1 if isprime(n) else n - 1 if n in S: return -1 S.add(n) return len(S) - 1
Comments