A376930 a(0)=0, a(1)=1; for n>1, a(n) = a(n-1)+a(n-2), except where a(n-1) is a prime greater than 2, in which case a(n) = a(n-1)-a(n-2).
0, 1, 1, 2, 3, 1, 4, 5, 1, 6, 7, 1, 8, 9, 17, 8, 25, 33, 58, 91, 149, 58, 207, 265, 472, 737, 1209, 1946, 3155, 5101, 1946, 7047, 8993, 16040, 25033, 8993, 34026, 43019, 8993, 52012, 61005, 113017, 52012, 165029, 217041, 382070, 599111, 981181, 1580292, 2561473
Offset: 0
Keywords
Examples
a(2) = a(1) + a(0) [as a(1) is not a prime > 2] = 1 + 0 = 1. a(3) = a(2) + a(1) [as a(2) is not a prime > 2] = 1 + 1 = 2. a(4) = a(3) + a(2) [as a(3) is not a prime > 2] = 2 + 1 = 3. a(5) = a(4) - a(3) [as a(4) is a prime > 2] = 3 - 2 = 1.
Links
- Robert Israel, Table of n, a(n) for n = 0..4810
Programs
-
Maple
f:= proc(n) option remember; if procname(n-1) > 2 and isprime(procname(n-1)) then procname(n-1) - procname(n-2) else procname(n-1) + procname(n-2) fi end proc: f(0):= 0: f(1):= 1: seq(f(i),i=0..100); # Robert Israel, Nov 12 2024
-
Mathematica
s={0,1};Do[If[PrimeQ[s[[-1]]]&&s[[-1]]>2,AppendTo[s,s[[-1]]-s[[-2]]],AppendTo[s,s[[-1]]+s[[-2]]] ],{n,48}];s (* James C. McMahon, Nov 07 2024 *)
-
Python
from sympy import isprime from itertools import islice def agen(): # generator of terms a = [0, 1] yield from a while True: an = a[-1]+a[-2] if a[-1] < 3 or not isprime(a[-1]) else a[-1]-a[-2] yield an a = [a[-1], an] print(list(islice(agen(), 50))) # Michael S. Branicky, Oct 11 2024
Comments