# Floor function summation[difficult]

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.

• Is there a good reason not to simply automate the computation? – lulu May 16 at 17:13
• It is a homework question. – PranavGupta53535 May 16 at 17:15
• Wolfram Alpha – Robert Israel May 16 at 17:50

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).

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)$$