login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

A051352
a(0) = 0; for n>0, a(n) = a(n-1) + n if n not prime else a(n-1) - n.
5
0, 1, -1, -4, 0, -5, 1, -6, 2, 11, 21, 10, 22, 9, 23, 38, 54, 37, 55, 36, 56, 77, 99, 76, 100, 125, 151, 178, 206, 177, 207, 176, 208, 241, 275, 310, 346, 309, 347, 386, 426, 385, 427, 384, 428, 473, 519, 472, 520, 569, 619, 670, 722, 669, 723, 778
OFFSET
0,4
COMMENTS
Sequence is not monotonic.
Difference between sum of nonprime numbers and prime numbers <= n. - Zak Seidov, Sep 27 2003
LINKS
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
a(n) = A000217(n) - 2*A034387(n). - Michel Marcus, Jun 24 2024
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