Evaluate $\sum_{r=1}^{502} \lfloor \frac{305r}{503} \rfloor$. The question is to find the value of —
$$\sum_{r=1}^{502} \Big \lfloor \frac{305r}{503}\Big \rfloor$$
The answer is pretty big, so I don't think trial and error will work here. I seriously can't come up with a solution to this problem. I have asked plenty of floor function questions (you can check my profile), but this one is quiet different. Can someone please help me out? Even a hint is greatly appreciated.
 A: Here is one way: use Pick's theorem on the triangle with vertices $(0,0), (503,0), (503,305)$.
Or you can do it more algebraically by noting
$$
\left\lfloor\frac{305 r}{503}\right\rfloor + \left\lfloor\frac{305(503-r)}{503}\right\rfloor = 305-1=304
$$
for all $1\leq r\leq 502$ (since $503$ is prime).
A: One can prove the following formula (for, say, positive integers $a, b, c$):
$$\sum_{k=0}^{b-1}\Big\lfloor\frac{ak+c}{b}\Big\rfloor=\frac{(a-1)(b-1)+d-1}{2}+d\Big\lfloor\frac{c}{d}\Big\rfloor,\qquad d=\gcd(a,b)$$
A: This is a junior problem (China /1986) check the solution of (example 7,page 41)  here,  Since all real numbers $x$ and $y$ are not integers but $x+y$ is integer then : $\left\lfloor \sqrt{x}\right\rfloor+\left\lfloor \sqrt{y}\right\rfloor=x+y-1$ since
$\{x\}+ \{y\}=1$, Since $\frac{305r}{503}+\frac{305(503-r)}{503}=305, 1\leq r\leq 502$ then we have :
\begin{align*}
  &  S=\left\lfloor \frac{305}{503}\right\rfloor+\left\lfloor \frac{305\times 2}{503}\right\rfloor+\cdots +\left\lfloor \frac{305\times 502}{503}\right\rfloor  \\&=\Bigg(\left\lfloor \frac{305\times 1}{503}\right\rfloor+\left\lfloor \frac{305\times 502}{503}\right\rfloor \Bigg)+\cdots \Bigg(\left\lfloor \frac{305\times 251}{503}\right\rfloor+\left\lfloor\frac{305\times252}{503}\right\rfloor \Bigg) \\&=304 \times 251 \\&=76304
\end{align*}
