login
a(0) = 2; a(n) = a(n - 1) * 2 + 1 if a(n - 1) is prime, or a(n - 1) / (smallest prime factor) if it is composite.
1

%I #11 May 09 2021 08:18:32

%S 2,5,11,23,47,95,19,39,13,27,9,3,7,15,5,11,23,47,95,19,39,13,27,9,3,7,

%T 15,5,11,23,47,95,19,39,13,27,9,3,7,15,5,11,23,47,95,19,39,13,27,9,3,

%U 7,15,5,11,23,47,95,19,39,13,27,9,3,7,15,5,11,23,47,95,19,39,13,27,9,3,7

%N a(0) = 2; a(n) = a(n - 1) * 2 + 1 if a(n - 1) is prime, or a(n - 1) / (smallest prime factor) if it is composite.

%C a(n) repeats itself after 14 iterations. Peak is a(5) = 95.

%C The function is similar in nature to Collatz's 3x+1 problem, except that it deals with primality instead of parity.

%H Wikipedia, <a href="http://en.wikipedia.org/en/wiki/Divisor">Divisor</a>

%H Wikipedia, <a href="http://en.wikipedia.org/en/wiki/Prime_number">Prime number</a>

%e a(0) = 2

%e a(1) = 2 * 2 + 1 = 5, because a(0) was prime.

%e a(2) = 5 * 2 + 1 = 11, because a(1) was prime.

%e ...

%e a(6) = 95 / 5 = 19, because the smallest prime factor of a(5) was 5.

%t NestList[If[PrimeQ[#],2#+1,#/FactorInteger[#][[1,1]]]&,2,80] (* or *) PadRight[{2},80,{15,5,11,23,47,95,19,39,13,27,9,3,7}] (* _Harvey P. Dale_, Jun 14 2020 *)

%o (Python)

%o import math

%o from sympy import isprime

%o a = [2]

%o while not a[ -1] in a[:-1]:

%o if isprime(a[ -1]):

%o a.append(a[ -1] * 2 + 1)

%o else:

%o for div in range(2, int(math.sqrt(a[ -1])) + 1):

%o if not a[ -1] % div:

%o a.append(a[ -1] // div)

%o break

%o print(a)

%K easy,nonn

%O 0,1

%A _Grant Garcia_, Sep 30 2010