0
$\begingroup$

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.

  • 2
    Is that a _still ongoing_ "challenge"?2017-02-13
  • 1
    @Rohan makes me wonder if the other question was an excuse to have other complete a challenge for the OP or if it was legitimate research...2017-02-13
  • 0
    Yes it is. The answer posted in the existing thread was perfect. Thanks for your help, it is very much appreciated!2017-02-13

0 Answers 0