OFFSET
0,2
COMMENTS
This is like the Fibonacci sequence but subtraction replaces addition when neither of the preceding two terms are prime numbers.
LINKS
Paul Tek, Table of n, a(n) for n = 0..1000
FORMULA
a(0) = 1, a(1) = 2, a(n) = a(n-1) + a(n-2) unless both a(n-1) and a(n-2) are composite, then a(n) = a(n-1) - a(n-2).
EXAMPLE
a(6) = 21 because a(5)=13 is prime and 13 + 8 = 21.
a(7) = 34 because a(5) is prime and 21 + 13 = 34.
a(8) = 13 because neither a(6) nor a(7) is prime and 34 - 21 = 13.
MATHEMATICA
modFibo[0] := 1; modFibo[1] := 2; modFibo[n_] := modFibo[n] = modFibo[n - 1] + (-1)^(Boole[Not[PrimeQ[modFibo[n - 1]] || PrimeQ[modFibo[n - 2]]]])modFibo[n - 2]; Table[modFibo[n], {n, 0, 49}] (* Alonso del Arte, Jan 31 2014 *)
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
Stephen McDonald, Jan 30 2014
STATUS
approved