login
A192439
a(n) = a(n-1) - a(n-2) if n is prime or a(n-1) + a(n-2) otherwise. a(1) = a(2) = 1.
1
1, 1, 0, 1, 1, 2, 1, 3, 4, 7, 3, 10, 7, 17, 24, 41, 17, 58, 41, 99, 140, 239, 99, 338, 437, 775, 1212, 1987, 775, 2762, 1987, 4749, 6736, 11485, 18221, 29706, 11485, 41191, 52676, 93867, 41191, 135058, 93867, 228925, 322792, 551717, 228925, 780642, 1009567
OFFSET
1,6
LINKS
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
Sequence in context: A030133 A139374 A111958 * A160187 A257879 A075616
KEYWORD
nonn
AUTHOR
Pasi Airikka, Jul 01 2011
STATUS
approved