login
a(n) = n + Sum_{k=1..n} (n mod k). Row sums of A372727.
23

%I #72 Jul 20 2024 06:10:31

%S 0,1,2,4,5,9,9,15,16,21,23,33,29,41,45,51,52,68,65,83,81,91,99,121,

%T 109,128,138,152,152,180,168,198,199,217,231,253,234,270,286,308,298,

%U 338,326,368,372,384,404,450,422,463,470,500,506,558,546,584,576,610,636

%N a(n) = n + Sum_{k=1..n} (n mod k). Row sums of A372727.

%C If the binary operation mod is defined n mod k = n if k = 0 and otherwise n - k*floor(n/k), as recommended in 'Concrete Mathematics' by Graham et. al. (p. 82), then a(n) = Sum_{k=0..n} (n mod k), for n >= 0. This definition is for example implemented in Sage, but not in Python. - _Peter Luschny_, Jul 19 2024

%C Previous name was "Sum of the element of the antidiagonals of the numerical array M(m, n) defined as follows. First row (M11, M12, ..., M1n): 1, 1, 1, 1, 1, 1, ... (all 1's). Second row (M21, M22, ..., M2n): 1, 2, 1, 2, 1, 2, ... (sequence 1, 2 repeated). Third row (M31, M32, ..., M3n): 1, 2, 3, 1, 2, 3, 1, 2, 3, ... (sequence 1, 2, 3 repeated). Fourth row (M41, M42, ..., M4n): 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, ... (sequence 1, 2, 3, 4 repeated). And so on."

%C Then the sequence is M(1,1), M(1,2) + M(2,1), M(1,3) + M(2,2) + M(3,1), etc., a(n) = Sum_{i=1..n} M(i, n-i+1).

%C This means: a(n) are the antidiagonal sums of the numerical array defined by M(n, k) = 1 + (k-1) mod n. - _Michel Marcus_, Sep 23 2013

%C The successive determinants of the arrays are the factorial numbers (A000142). - _Robert G. Wilson v_

%D Ronald L. Graham, Donald E. Knuth and Oren Patashnik, Concrete Mathematics, 2nd ed., Addison-Wesley, 1994, 34th printing 2022.

%H Robert Israel, <a href="/A111490/b111490.txt">Table of n, a(n) for n = 0..10000</a>

%F a(n) = n + A004125(n). - _Juri-Stepan Gerasimov_, Aug 30 2009

%F a(n) = Sum_{i=1..n+1} (n mod i). - _Wesley Ivan Hurt_, Dec 05 2014

%F G.f.: 2*x/(1-x)^3 - (1-x)^(-1)*Sum_{k>=1} k*x^k/(1-x^k). - _Robert Israel_, Oct 11 2015

%F a(n) = (1 - Pi^2/12) * n^2 + O(n*log(n)). - _Amiram Eldar_, Dec 04 2023

%e If the mod operation is defined according CMath, and n = 11, then the list

%e [n mod k : k = 0..n] = [11, 0, 1, 2, 3, 1, 5, 4, 3, 2, 1, 0], and the total of this list is a(11) = 33.

%p A111490:=n->add(n mod i, i=1..n+1): seq(A111490(n), n=0..100); # _Wesley Ivan Hurt_, Dec 05 2014

%p seq(n + add(irem(n, k), k = 2..n-1), n = 0..58); # _Peter Luschny_, Jul 19 2024

%t t = Table[Flatten@Table[Range@n, {m, Ceiling[99/n]}], {n, 99}]; f[n_] := Sum[ t[[i, n - i + 1]], {i, n}]; Array[f, 58] (* _Robert G. Wilson v_, Nov 22 2005 *)

%t (* to view table *) Table[Flatten@Table[Range@n, {m, Ceiling[40/n]}], {n, 10}] // TableForm

%o (PARI) vector(100, n, n + sum(k=2, n, n % k)) \\ _Altug Alkan_, Oct 12 2015

%o (PARI) a(n) = sum(k=1, n, 2*k-sigma(k)); \\ _Michel Marcus_, Oct 11 2015

%o (Python)

%o from math import isqrt

%o def A111490(n): return n*(n+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_, Nov 01 2023

%o (Python)

%o def a(n): return sum(n % k if k else n for k in range(n))

%o print([a(n) for n in range(59)]) # _Peter Luschny_, Jul 19 2024

%o (SageMath)

%o def a(n): return sum(n.mod(k) for k in range(n))

%o print([a(n) for n in srange(59)]) # _Peter Luschny_, Jul 19 2024

%Y Partial sums of A033879. - _Gionata Neri_, Sep 10 2015

%Y Cf. A000142, A004125, A372727 (triangle).

%K nonn,easy

%O 0,3

%A _Paolo P. Lava_ and _Giorgio Balzarotti_, Nov 21 2005

%E Edited and extended by _Robert G. Wilson v_, Nov 22 2005

%E Prepending a(0) = 0 and new name using a formula of _Juri-Stepan Gerasimov_ by _Peter Luschny_, Jul 19 2024