OFFSET
1,1
LINKS
Hans Havermann, Table of n, a(n) for n = 1..71 (terms 1..60 from Michael S. Branicky)
Eric Angelini, Do we yo-yo?, personal blog of the author, July 2024.
EXAMPLE
As a(1) = 3 has an absolute prime value, we subtract the 3rd prime from 3 to form the next term: 3 - 5 = -2;
as a(2) = -2 has an absolute prime value, we subtract the 2nd prime from -2 to form the next term: -2 - 3 = -5;
as a(3) = -5 has an absolute prime value, we subtract the 5th prime from -5 to form the next term: -5 - 11 = -16;
as a(4) = -16 has an absolute nonprime value, we add the 16th nonprime to -16 to form the next term: -16 + 25 = 9; etc.
MATHEMATICA
np[n_]:=FixedPoint[n+PrimePi[#]&, n+PrimePi[n]]; (* A018252 *) seq[n_]:=If[PrimeQ[Abs[n]], n-Prime[Abs[n]], n+np[Abs[n]]]; NestList[seq, 3, 52] (* Hans Havermann, Jul 23 2024 *)
PROG
(Python)
from itertools import islice
from sympy import prime, composite, isprime
def agen(): # generator of terms
an = 3
while True:
yield an
if isprime(abs(an)):
an = an - prime(abs(an))
else:
an += composite(abs(an)-1) if abs(an) > 1 else 1
print(list(islice(agen(), 38))) # Michael S. Branicky, Jul 22 2024
CROSSREFS
KEYWORD
sign
AUTHOR
Eric Angelini and Hans Havermann, Jul 21 2024
STATUS
approved