TITLE: How to count this in a faster way?
QUESTION [1 upvotes]: It's a homework problem, it took me 20mins to do it,
and what's even worse is that I didn't get the correct exact answer....
(we are only asked to give an approximate number, I didn't lose any point tho...)
initially, a=0, b=0, C=0.
C is used to count the number of times of algorithm. 
when a=0, b start from 0, 1, 2,... to whenever a^2+b^2 >= 2500, then stop
then a=1, b start from 0, 1, 2,... to whenever a^2+b^2 >= 2500, then stop
.
.
.
.
keep going on, and the last loop will be a=49, b=0,1,2,...9.
The question is the value of C.
I did it step by step, like when a=3, a^2=9,
then doing some "square" & "subtract" work knowing that b stops at b=49.
I'm wondering if there's a SMART way to do it fast and correctly without computers...
Thanks!!

REPLY [0 votes]: For any particular $a$, $b$ can go up to the largest integer below $\sqrt{2500-a^2}$. So for any particular $a$ we have the count equal to $\lfloor\sqrt{(2500-a^2)}\rfloor$. The half brackets mean the floor function. Then you would sum this up from $a=0$ up to $a=49$. (You could also sum to $a=50$, but the floor of 0 is 0.)
Plugging into wolframalpha I get 
$\sum_{a=0}^{a=49} \lfloor\sqrt{(2500-a^2)}\rfloor = 1961$
This is assuming that C is not incremented when $a^2+b^2 \ge 2500$. If C is incremented on the iteration on which this condition is satisfied, then we use the ceiling function instead to get $\sum_{a=0}^{a=49} \lceil\sqrt{(2500-a^2)}\rceil = 2006$
{"set_name": "stack_exchange", "score": 1, "question_id": 514195}