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”).

A recurrence relation conditioned on the primality of the preceding terms.
1

%I #18 Jul 23 2014 15:10:21

%S 1,2,3,5,8,13,21,34,13,47,60,107,167,274,441,167,608,775,167,942,1109,

%T 2051,3160,1109,4269,5378,1109,6487,7596,1109,8705,9814,1109,10923,

%U 12032,1109,13141,14250,1109,15359,16468,31827,15359,47186,62545,15359,77904,93263,171167,264430

%N A recurrence relation conditioned on the primality of the preceding terms.

%C This is like the Fibonacci sequence but subtraction replaces addition when neither of the preceding two terms are prime numbers.

%H Paul Tek, <a href="/A236768/b236768.txt">Table of n, a(n) for n = 0..1000</a>

%F 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).

%e a(6) = 21 because a(5)=13 is prime and 13 + 8 = 21.

%e a(7) = 34 because a(5) is prime and 21 + 13 = 34.

%e a(8) = 13 because neither a(6) nor a(7) is prime and 34 - 21 = 13.

%t 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 *)

%K nonn,easy

%O 0,2

%A _Stephen McDonald_, Jan 30 2014