OFFSET
1,3
COMMENTS
n - 2*[ n/2 ] + 3*[ n/3 ] - ... + m*n*[ n/n ], where m = (-1)^(n+1).
LINKS
Seiichi Manyama, Table of n, a(n) for n = 1..10000
FORMULA
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
KEYWORD
sign
AUTHOR
EXTENSIONS
Edited by Robert G. Wilson v, Aug 17 2002
STATUS
approved