OFFSET
0,4
COMMENTS
Sequence is not monotonic.
Difference between sum of nonprime numbers and prime numbers <= n. - Zak Seidov, Sep 27 2003
LINKS
William A. Tedeschi, Table of n, a(n) for n = 0..10000
FORMULA
a(n) = a(n-1) + n * (1 - 2*A010051(n)) = a(n-1) + n * (2*A005171(n) - 1) = a(n-1) + n * (A005171(n) - A010051(n)). - Reinhard Zumkeller, Nov 25 2009
MAPLE
A034387 := proc(n)
option remember;
if n <= 1 then
0;
else
procname(n-1)+ `if`(isprime(n), n, 0)
end if;
end proc:
A051352 := proc(n)
n*(n+1)/2 - 2*A034387(n) ;
end proc:
seq(A051352(n), n=0..40) ; # R. J. Mathar, Jun 26 2024
MATHEMATICA
a[0]=0; a[n_]:=a[n]=If[PrimeQ[n], a[n-1]-n, a[n-1]+n]; Table[a[i], {i, 0, 60}] (* Harvey P. Dale, Apr 07 2011 *)
nxt[{n_, a_}]:={n+1, If[PrimeQ[n+1], a-n-1, a+n+1]}; NestList[nxt, {0, 0}, 60][[All, 2]] (* Harvey P. Dale, Sep 07 2022 *)
PROG
(Haskell)
a051352 n = a051352_list !! n
a051352_list = 0 : zipWith (+)
(a051352_list) (zipWith (*) [1..] $ map ((1 -) . (* 2)) a010051_list)
-- Reinhard Zumkeller, Jan 02 2015
(PARI) a(n) = my(v=primes([1, n])); n*(n+1)/2 -2*vecsum(v); \\ Michel Marcus, Jun 24 2024
CROSSREFS
KEYWORD
sign,easy,nice
AUTHOR
Armand Turpel armandt(AT)unforgettable.com
STATUS
approved