login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

A175871
a(0) = 2; a(n) = a(n - 1) * 3 + 1 if a(n - 1) is prime, or a(n - 1) / (smallest prime factor) if it is composite.
2
2, 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8
OFFSET
0,1
COMMENTS
a(n) repeats itself after 16 iterations. Peak is a(6) = 52.
The function is similar in nature to Collatz's 3x+1 problem, except that it deals with primality instead of parity.
LINKS
EXAMPLE
a(0) = 2
a(1) = 2 * 3 + 1 = 7, because a(0) was prime.
a(2) = 7 * 3 + 1 = 22, because a(1) was prime.
a(3) = 22 / 2 = 11, because the smallest prime factor of a(2) was 2.
MATHEMATICA
NestList[If[PrimeQ[#], 3#+1, #/FactorInteger[#][[1, 1]]]&, 2, 80] (* or *) PadRight[{}, 80, {2, 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4}] (* Harvey P. Dale, Aug 05 2023 *)
PROG
(Python)
import math
from sympy import isprime
a = [2]
while not a[ -1] in a[:-1]:
if isprime(a[ -1]):
a.append(a[ -1] * 3 + 1)
else:
for div in range(2, int(math.sqrt(a[ -1])) + 1):
if not a[ -1] % div:
a.append(a[ -1] // div)
break
print(a)
CROSSREFS
Sequence in context: A076716 A088591 A229493 * A137107 A284921 A174236
KEYWORD
easy,nonn
AUTHOR
Grant Garcia, Oct 02 2010
STATUS
approved