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”).

A024919
a(n) = Sum_{k=1..n} (-1)^k*k*floor(n/k).
12
-1, 0, -4, 1, -5, -1, -9, 4, -9, -3, -15, 5, -9, -1, -25, 4, -14, -1, -21, 9, -23, -11, -35, 17, -14, 0, -40, 0, -30, -6, -38, 23, -25, -7, -55, 10, -28, -8, -64, 14, -28, 4, -40, 20, -58, -34, -82, 34, -23, 8, -64, 6, -48, -8, -80, 24, -56, -26, -86, 34, -28, 4, -100, 25, -59
OFFSET
1,3
COMMENTS
n - 2*[ n/2 ] + 3*[ n/3 ] - ... + m*n*[ n/n ], where m = (-1)^(n+1).
LINKS
FORMULA
a(n) = 4*A024916(floor(n/2)) - A024916(n). - Vladeta Jovovic, Oct 15 2002
G.f.: 1/(1-x) * Sum_{n>=1} n*x^n*(3*x^n-1)/(1-x^(2*n)). - Vladeta Jovovic, Oct 15 2002
G.f.: -1/(1-x) * Sum_{k>=1} x^k/(1+x^k)^2 = 1/(1-x) * Sum_{k>=1} k * (-x)^k/(1-x^k). - Seiichi Manyama, Oct 29 2023
MATHEMATICA
f[n_] := Sum[(-1)^i*i*Floor[n/i], {i, 1, n}]; Table[ f[n], {n, 1, 85}]
PROG
(PARI) a(n) = sum(k=1, n, (-1)^k*k*floor(n/k));
(Magma) [&+[(-1)^k*k*(n div k): k in [1..n]]: n in [1..70]]; // Vincenzo Librandi, Jul 28 2019
(Python)
from math import isqrt
def A024919(n): return (-(s:=isqrt(m:=n>>1))**2*(s+1) + sum((q:=m//k)*((k<<1)+q+1) for k in range(1, s+1))<<1)+((s:=isqrt(n))**2*(s+1)-sum((q:=n//k)*((k<<1)+q+1) for k in range(1, s+1))>>1) # Chai Wah Wu, Oct 22 2023
CROSSREFS
The zeros are A072663.
Partial sums of A002129.
Sequence in context: A101322 A029644 A345305 * A328385 A328099 A003415
KEYWORD
sign
EXTENSIONS
Edited by Robert G. Wilson v, Aug 17 2002
STATUS
approved