As part of a Google foobar challenge I have been asked to calculate:
$$\sum_{k=1}^{n} \left\lfloor {k*\sqrt{2}} \right\rfloor$$
for numbers up to $10^{100}$
My attempt so far resulted in imprecise results:
Using the formula $\sum_{k=1}^{n-1} \left\lfloor \frac{km}{n} \right\rfloor = \frac{1}{2}(m - 1)(n - 1)$
I made this calculation: $ \frac{1}{2} ((n+1)*\sqrt{2}-1)*n $
The results needed to be rounded (I suppose because of the irrationality of $\sqrt{2}$) and were incorrect in about 10% of test cases.
Thanks in advance!
Note: I've looked at many of the threads regarding sum of floors and wasn't able to find a closed form that yields better accuracy.