0

So I am trying to figure out a summation of all odd squares up to n. I.E if n = 9, then the output should be 10 (the odd squares <= 9 are 1 and 9, therefore 1+9 = 10). Can anyone help me out? I can't wrap my head around this one. I did one fore the summation of odd squares for n times, but this one is proving more difficult.

Jacob R
  • 101
  • 1
    Hint: the largest integer whose square is not larger than $,10,$ is $,\lfloor \sqrt{10}\rfloor,$. – dxiv May 14 '17 at 22:29
  • There's a closed form: http://m.wolframalpha.com/input/?i=sum+%282n%2B1%29%5E2+from+0+to+i&x=2&y=11 – N74 May 14 '17 at 22:43
  • I am trying to add the odd squares that are less than or equal to n, that closed form is adding odd squares up to n as the incrementer. Like my example, if i set n=9, then the output should be ten, because the odd squares <= 9 are 1 and 9, therefore the summation of n=9 should be 10 – Jacob R May 14 '17 at 23:22

1 Answers1

0

$f(n) = [\sum_{k=1}^{\lfloor \sqrt{n}\rfloor}(k)^2] - [\sum_{k=1}^{\lfloor\sqrt{n}/2\rfloor}(2k)^2]$

The first sum should find all the squares, the second should remove all those with even numbers.

The sum of squares formula is ${n(n+1)(2n+1) \over 6}$, so we can simplify this down to

${\lfloor \sqrt{n}\rfloor}({\lfloor \sqrt{n}\rfloor}+1)(2*{\lfloor \sqrt{n}\rfloor} + 1) \over 6$ $-$ $4*{\lfloor \sqrt{n}/2\rfloor}({\lfloor \sqrt{n}/2\rfloor}+1)(2*{\lfloor \sqrt{n}/2\rfloor} + 1) \over 6 $.

John Lou
  • 2,388
  • 13
  • 16