login
This site is supported by donations to The OEIS Foundation.

 

Logo


Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A192439 a(n) = a(n-1) - a(n-2) is 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 (list; graph; refs; listen; history; text; internal format)
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.

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

Cf. A010051, A000045.

Sequence in context: A030133 A139374 A111958 * A160187 A257879 A075616

Adjacent sequences:  A192436 A192437 A192438 * A192440 A192441 A192442

KEYWORD

nonn

AUTHOR

Pasi Airikka, Jul 01 2011

STATUS

approved

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recent | More pages
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified October 23 18:36 EDT 2018. Contains 316529 sequences. (Running on oeis4.)