login
a(0) = 0; for n>0, a(n) = a(n-1) + n if n not prime else a(n-1) - n.
5

%I #31 Jun 26 2024 10:34:03

%S 0,1,-1,-4,0,-5,1,-6,2,11,21,10,22,9,23,38,54,37,55,36,56,77,99,76,

%T 100,125,151,178,206,177,207,176,208,241,275,310,346,309,347,386,426,

%U 385,427,384,428,473,519,472,520,569,619,670,722,669,723,778

%N a(0) = 0; for n>0, a(n) = a(n-1) + n if n not prime else a(n-1) - n.

%C Sequence is not monotonic.

%C Difference between sum of nonprime numbers and prime numbers <= n. - _Zak Seidov_, Sep 27 2003

%H William A. Tedeschi, <a href="/A051352/b051352.txt">Table of n, a(n) for n = 0..10000</a>

%F 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

%F a(n) = A000217(n) - 2*A034387(n). - _Michel Marcus_, Jun 24 2024

%p A034387 := proc(n)

%p option remember;

%p if n <= 1 then

%p 0;

%p else

%p procname(n-1)+ `if`(isprime(n), n, 0)

%p end if;

%p end proc:

%p A051352 := proc(n)

%p n*(n+1)/2 - 2*A034387(n) ;

%p end proc:

%p seq(A051352(n),n=0..40) ; # _R. J. Mathar_, Jun 26 2024

%t 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 *)

%t 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 *)

%o (Haskell)

%o a051352 n = a051352_list !! n

%o a051352_list = 0 : zipWith (+)

%o (a051352_list) (zipWith (*) [1..] $ map ((1 -) . (* 2)) a010051_list)

%o -- _Reinhard Zumkeller_, Jan 02 2015

%o (PARI) a(n) = my(v=primes([1, n])); n*(n+1)/2 -2*vecsum(v); \\ _Michel Marcus_, Jun 24 2024

%Y Cf. A005171, A010051.

%Y Cf. A000217, A034387.

%K sign,easy,nice

%O 0,4

%A Armand Turpel armandt(AT)unforgettable.com