OFFSET
0,4
COMMENTS
As n goes to infinity we have the asymptotic formula: a(n) ~ n * log(2).
LINKS
T. D. Noe, Table of n, a(n) for n = 0..10000
FORMULA
From Vladeta Jovovic, Oct 15 2002: (Start)
G.f.: 1/(1-x)*Sum_{n>=1} x^n/(1+x^n). (End)
a(n) = Sum_{n/2 < k < =n} d(k) - Sum_{1 < =k <= n/2} d(k), where d(k) = A000005(k). Also, a(n) = number of terms among {floor(n/k)}, 1<=k<=n, that are odd. - Leroy Quet, Jan 19 2006
From Ridouane Oudra, Aug 15 2019: (Start)
a(n) = Sum_{k=1..n} (floor(n/k) mod 2).
a(n) = (1/2)*(n + A271860(n)).
a(n) = Sum_{k=1..n} round(n/(2*k)) - floor(n/(2*k)), where round(1/2) = 1. (End)
EXAMPLE
a(5) = 4 because floor(5) - floor(5/2) + floor(5/3) - floor(5/4) + floor(5/5) - floor(5/6) + ... = 5 - 2 + 1 - 1 + 1 - 0 + 0 - 0 + ... = 4.
MAPLE
for n from 0 to 200 do printf(`%d, `, sum((-1)^(i+1)*floor(n/i), i=1..n)) od:
MATHEMATICA
f[list_, i_] := list[[i]]; nn = 200; a = Table[1, {n, 1, nn}]; b =
Table[If[OddQ[n], 1, -1], {n, 1, nn}]; Table[DirichletConvolve[f[a, n], f[b, n], n, m], {m, 1, nn}] // Accumulate (* Geoffrey Critzer, Mar 29 2015 *)
Table[Sum[Floor[n/k] - 2*Floor[n/(2*k)], {k, 1, n}], {n, 0, 100}] (* Vaclav Kotesovec, Dec 23 2020 *)
PROG
(PARI) { for (n=0, 10000, s=1; d=2; a=n; while ((f=floor(n/d)) > 0, a-=s*f; s=-s; d++); write("b059851.txt", n, " ", a); ) } \\ Harry J. Smith, Jun 29 2009
(Python)
from math import isqrt
def A059851(n): return ((t:=isqrt(m:=n>>1))**2<<1)-(s:=isqrt(n))**2+(sum(n//k for k in range(1, s+1))-(sum(m//k for k in range(1, t+1))<<1)<<1) # Chai Wah Wu, Oct 23 2023
(Magma)
A059851:= func< n | (&+[Floor(n/j)*(-1)^(j-1): j in [1..n]]) >;
[A059851(n): n in [1..80]]; // G. C. Greubel, Jun 27 2024
(SageMath)
def A059851(n): return sum((n//j)*(-1)^(j-1) for j in range(1, n+1))
[A059851(n) for n in range(81)] # G. C. Greubel, Jun 27 2024
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
Avi Peretz (njk(AT)netvision.net.il), Feb 27 2001
EXTENSIONS
More terms from James A. Sellers and Larry Reeves (larryr(AT)acm.org), Feb 27 2001
STATUS
approved