4

I need to evaluate the sum $$\sum_{i=1}^n i^2\cdot\lfloor{\frac ni}\rfloor$$ After a little bit of math I found that the above sum is equal to: $$\sum_{i=1}^n i\cdot n - \sum_{i=1}^ni\cdot (n\space mod \space i)$$ The first (left) sum has a closed form, $\frac {n^2\cdot (n+1)}{2}$, but what about the left?

I need this for computational use, for very large $n$, so performing the summation with $O(n)$ is probably the wrong approach, which is why I suspect it has a closed form, or at least another way to perform the summation with smaller complexity, perhaps $O(\sqrt n)$. If the sum to the right has no closed form, then is there any other way to evaluate the original sum?

Matan
  • 821
  • Starting with $i=1$ (to avoid the division by $0$) should give you the sequence A064602. – Raymond Manzoni Apr 24 '19 at 18:25
  • I've corrected the sums to start from $i=1$ rather than zero. I noticed the sequence on the OEIS, however the mentioned entry does not contain any notes as to how to reduce the computational complexity of the summation. It states more or less the same as I've written. @RaymondManzoni – Matan Apr 24 '19 at 18:30
  • 3
    For very large n very good approximation is: $\frac{1}{3}-\frac{n}{3}+\frac{n^3 \psi ^{(2)}(n)}{6}+\frac{n^3 \zeta (3)}{3}$ where $\psi ^{(2)}(n)$ is 2-th derivative of the digamma function. – Mariusz Iwaniuk Apr 24 '19 at 19:59
  • @MariuszIwaniuk can you please explain what this is exactly? I do recognize the zeta function, but I'm unfamiliar with digamma function. – Matan Apr 25 '19 at 13:13
  • $\int_1^{\infty } x^2 \left\lfloor \frac{n}{x}\right\rfloor , dx=\frac{1}{3}-\frac{n}{3}+\frac{n^3 \psi ^{(2)}(n)}{6}+\frac{n^3 \zeta (3)}{3}$.By Mathematica syntax: 1/3 - n/3 + (n^3*PolyGamma[2, n])/6 + n^3*Zeta[3]/3 where digamma function see here: http://mathworld.wolfram.com/PolygammaFunction.html – Mariusz Iwaniuk Apr 25 '19 at 16:12

2 Answers2

3

Regarding an $O(n^{1/2+\epsilon})$ computation... one can use $$\sum_{m=1}^{n}f(m)g(\lfloor n/m\rfloor)=\sum_{m=1}^{\lfloor n/(k+1)\rfloor}f(m)g(\lfloor n/m\rfloor)+\\+\sum_{r=1}^{k}g(r)\big(F(\lfloor n/r\rfloor)-F(\lfloor n/(r+1)\rfloor)\big),$$ where $f,g$ are functions of positive integers, $1\leqslant k\leqslant n$, and $F(n)=\displaystyle\sum_{m=1}^{n}f(m)$.

(Put $f(n)=n^2$, $g(n)=n$, $F(n)=n(n+1)(2n+1)/6$ and $k=\lfloor\sqrt{n}\rfloor$, say.)

UPDATE. The equation above is obtained as follows. If $1\leqslant m,r\leqslant n$ then $$\Big\lfloor\frac{n}{m}\Big\rfloor=r\iff mr\leqslant n<m(r+1)\iff\Big\lfloor\frac{n}{r+1}\Big\rfloor<m\leqslant\Big\lfloor\frac{n}{r}\Big\rfloor.$$ So, for $1\leqslant k\leqslant n$, splitting the range of summation in $\displaystyle\sum_{m=1}^{n}f(m)g(\lfloor n/m\rfloor)$ this way: $$\{m : 1\leqslant m\leqslant n\} = \left\{m : 1\leqslant m\leqslant\Big\lfloor\frac{n}{k+1}\Big\rfloor\right\}\cup\bigcup_{r=1}^{k}\left\{m : \Big\lfloor\frac{n}{r+1}\Big\rfloor<m\leqslant\Big\lfloor\frac{n}{r}\Big\rfloor\right\},$$ we get the expected.

metamorphy
  • 43,591
  • This turns out to be the right way to perform that summation. Could you please elaborate on this and how it is derived? Is this a generalized technique that always works and I can always use? – Matan Apr 24 '19 at 19:37
  • 1
    I've updated the answer with a hint on derivation (this idea shows up in some of the "Related" questions, and it appears I've already used it before). – metamorphy Apr 25 '19 at 03:26
2

Letting the summation begin with $i=1$ we obtain the sequence $$1, 6, 16, 37, 63, 113, 163, 248, 339, 469, 591, 801, 971, 1221, 1481, \ 1822, 2112, 2567, 2929, 3475\ \ldots$$ This sequence is listed under A064602 at OEIS and is the sequence of partial sums of A001157. What they are saying at OEIS is not very hopeful for a simple expression producing this sequence.

  • Thank you for the reply. I noticed the entry, as well as the expressions they provided. I know for sure a solution to my question exists, and because the entry did not provide me with the insight I needed, I've come here. – Matan Apr 24 '19 at 18:54