OFFSET
2,1
COMMENTS
a(n) is prime iff n is prime.
LINKS
Charles R Greathouse IV, Table of n, a(n) for n = 2..10000
Vladimir Shevelev, Several results on sequences which are similar to the positive integers, arXiv:0904.2101 [math.NT], 2009.
FORMULA
a(n+1) = min{m>a(n), m is prime}, if n+1 is prime; otherwise, a(n+1) = min{m>a(n), m is composite}.
EXAMPLE
For n = 6, since n is composite, a(6) is the smallest composite number greater than a(6-1) = a(5) = 7, so a(6) = 8. For n = 11, since n is prime, a(11) is the smallest prime number greater than a(11-1) = a(10) = 15, so a(12) = 17. - Michael B. Porter, Sep 04 2016
MAPLE
A159559 := proc(n) option remember; if n = 2 then 3; else for a from procname(n-1)+1 do if isprime(n) and isprime(a) then RETURN(a) ; elif not isprime(n) and not isprime(a) then RETURN(a) ; fi; od: fi; end: seq(A159559(n), n=2..100) ; # R. J. Mathar, Jul 28 2009
MATHEMATICA
a[2] = 3;
a[n_] := a[n] = If[PrimeQ[n], NextPrime[a[n-1]], NestWhile[#+1&, a[n-1]+1, PrimeQ]];
Map[a, Range[2, 100]] (* Peter J. C. Moses, Sep 19 2013 *)
PROG
(PARI) nextcomposite(n)=if(n<4, return(4)); n=ceil(n); if(isprime(n), n+1, n)
first(n)=my(v=vector(n)); v[2]=3; for(k=3, n, v[k]=if(isprime(k), nextprime(v[k-1]+1), nextcomposite(v[k-1]+1))); v[2..n] \\ Charles R Greathouse IV, Sep 21 2016
CROSSREFS
KEYWORD
nonn
AUTHOR
Vladimir Shevelev, Apr 15 2009, May 04 2009
EXTENSIONS
More terms from R. J. Mathar, Jul 28 2009
STATUS
approved