OFFSET
1,6
LINKS
Reinhard Zumkeller, Table of n, a(n) for n = 1..1000
FORMULA
a(n) = a(n-1) + a(n-2), if n is nonprime.
a(n) = a(n-1) - a(n-2), if n is prime.
a(1) = a(2) = 1.
a(n) >> x^n, with x = 1.28743... the largest real root of x^6 - x^5 + x^4 - x^3 + x^2 - x = 2. - Charles R Greathouse IV, Jul 01 2011
EXAMPLE
a(1) = 1, a(2) = 1.
a(3) = 1 - 1 = 0, as n=3 is prime.
a(4) = 0 + 1 = 1, as n=4 is nonprime.
a(5) = 1 - 0 = 1, as n=5 is prime.
a(6) = 1 + 1 = 2, as n=6 is nonprime.
MATHEMATICA
nxt[{n_, a_, b_}]:={n+1, b, If[PrimeQ[n+1], b-a, b+a]}; NestList[nxt, {2, 1, 1}, 50][[All, 2]] (* Harvey P. Dale, Dec 23 2022 *)
PROG
(MATLAB)
a(1)=1; a(2)=1;
for i=3:n,
true = isprime(n) ;
if true,
a(i)=a(i-1)-a(i-2) ;
else
a(i)=a(i-1)+a(i-2) ;
end
end
% isprime returns 1 if n is prime, else 0.
(PARI) a=vector(100); a[1]=a[2]=1; for(n=3, #a, a[n]=a[n-1]+(1-2*isprime(n))*a[n-2]); a \\ Charles R Greathouse IV, Jul 01 2011
CROSSREFS
KEYWORD
nonn
AUTHOR
Pasi Airikka, Jul 01 2011
STATUS
approved