What is the sum of this modulo series?

318 Views Asked by At

Given only a large integer upto $ 10^{18} $ , what can be an efficient way to calculate $$ \sum_{k=1}^{\left \lfloor \sqrt{N} \right \rfloor} \left ( N \ mod \ k^{2} \right ) $$ Note that for a local machine, computation can go upto $ 10^{6} $ iterations.

1

There are 1 best solutions below

12
On BEST ANSWER

It might be worth rewriting the sum with the modulo as the floor of integer division, $\displaystyle N\lfloor\sqrt{N}\rfloor-\sum_{k=1}^{\lfloor\sqrt{N}\rfloor}k^{2}\left\lfloor\frac{N}{k^{2}}\right\rfloor$. You could then attempt to partition the sum into subsets of $k$ such that $\displaystyle\left\lfloor\frac{N}{k^{2}}\right\rfloor$ is a certain integer, $1,2,3,\ldots$, and then sum those simpler sums individually. User alex.jordan has described a similar method in (Question 3618219).