OFFSET
1,1
LINKS
Harvey P. Dale, Table of n, a(n) for n = 1..1000
FORMULA
EXAMPLE
The first four primes are 2, 3, 5, 7 and the first four nonprimes are 1, 4, 6, 8. Hence a(1) = 2 + 1 = 3, a(2) = 3 + 4 = 7, a(3) = 5 + 6 = 11 and a(4) = 7 + 8 = 15.
MATHEMATICA
ppnp[terms_] := Module[{prs = Prime[Range[terms]], nprs, lenprs}, nprs = Complement[Range[Prime[terms]], prs]; lenprs = Length[prs]; Total /@ Thread[{prs, Take[nprs, lenprs]}]]; ppnp[60] (* Harvey P. Dale, Nov 29 2011 *)
PROG
(Python)
from sympy import prime, composite
def A022797(n): return 3 if n == 1 else prime(n)+composite(n-1) # Chai Wah Wu, Aug 30 2021
(PARI) a(n) = my(nonprime(i)=my(p=1, q=i); while(p!=q, p=q; q=i+primepi(p)); q); prime(n) + nonprime(n); \\ Ruud H.G. van Tol, Feb 16 2024
(PARI) alist(N) = my(r=primes(N), q=3); r[1]+=1; for(n=2, N, if(isprime(q++), q++); r[n]+=q); r; \\ Ruud H.G. van Tol, Feb 16 2024
CROSSREFS
KEYWORD
nonn,easy,nice
AUTHOR
STATUS
approved