TITLE: Evaluation of the sum $\sum_{k = 0}^{\lfloor a/b \rfloor} \left \lfloor \frac{a - kb}{c} \right \rfloor$
QUESTION [12 upvotes]: Let $a, b$ and $c$ be positive integers. Recall that the greatest common divisor (gcd) function has the following representation:
\begin{eqnarray}
\textbf{gcd}(b,c) = 2 \sum_{k = 1}^{c- 1} \left \lfloor \frac{kb}{c} \right \rfloor + b + c - bc
\end{eqnarray}
as shown by Polezzi, where $\lfloor \cdot \rfloor$ denotes the floor function. In trying to generalize the formula I came across the following summation
\begin{eqnarray}
\sum_{k = 0}^{\lfloor a/b \rfloor} \left \lfloor \frac{a - kb}{c} \right \rfloor.
\end{eqnarray}
I can prove the following identity for real $x$,
\begin{eqnarray}
\sum_{k = 0}^{c-1} \left \lceil \frac{x - kb}{c} \right \rceil = d \left \lceil \frac{x}{d} \right \rceil - \frac{(b-1)(c-1)}{2} - \frac{d-1}{2},
\end{eqnarray}
where $\lceil \cdot \rceil$ denotes the ceiling function and $d = \text{gcd}(b,c)$. (Note that in the first summation the upper index is in general independent of $c$.) Ideas or reference suggestions are certainly appreciated. Thanks in advance! 
Update I can prove the identity
\begin{eqnarray}
\sum_{k = 0}^{c-1} \left \lfloor \frac{x - kb}{c} \right \rfloor = d \left \lfloor \frac{x}{d} \right \rfloor - \frac{(b+1)(c-1)}{2} + \frac{d-1}{2},
\end{eqnarray}
where $d = \text{gcd}(b,c)$. There is another identity which might be useful. If $n = c \ell +r$ with $0 \leq r < c$, then
\begin{eqnarray}
\sum_{k = 1}^{n} \left \lfloor \frac{k}{c} \right \rfloor = c \binom{\ell}{2} + (r + 1) \ell.
\end{eqnarray}
Update 2 Ok, so I can prove that for real $x, y > 0$,
\begin{eqnarray}
\sum_{k = 0}^{\lfloor y \rfloor} \left \lfloor x + \frac{k}{y} \right \rfloor = \lfloor xy + (\lceil y \rceil - y) \lfloor x + 1 \rfloor \rfloor + \chi_{\mathbb{N}}(y)(\lfloor x \rfloor + 1),
\end{eqnarray}
where $\chi_{\mathbb{N}}$ denotes the characteristic function of the positive integers. My original problem (and a nice generalization of it) will be in hand if I can evaluate the following minor generalization: For real $x, y  > 0$ and $n \in \mathbb{Z}_{\geq 0}$,
\begin{eqnarray}
\sum_{k = 0}^{n} \left \lfloor x + \frac{k}{y} \right \rfloor.
\end{eqnarray}
Again, any help is certainly appreciated!

REPLY [6 votes]: I would like to summarise and extend the results of my previous answer in a new answer as I prefer to keep the original in its current form to prevent it from turning into my magnum opus.
Theorem 1:
For positive integers $a, b$ and $c$ where $ d=\text{gcd}(b,c), $ $u=c/d,$
$t= \lfloor a/b \rfloor $ and $ a \equiv \lambda \textrm{ mod } d, $ where
$ 0 \le \lambda < d,$ and $ u \, | \, (t+1) $ we have
$$ \sum_{k=0}^{t} \left \lfloor \frac{a - kb}{c} \right \rfloor =
\frac{t+1}{c} \left \lbrace a - \frac{tb}{2} - \frac{c-d}{2} - \lambda \right \rbrace . $$
So far, the above theorem and its proof are included in my previous answer. The rest is new.
Theorem 2: 
Along with the definitions in theorem 1, let $ a \equiv r \textrm{ mod } c, $ where $ 0 \le r < c $ and $ u \, | \, t $ then
$$ \sum_{k=0}^{t} \left \lfloor \frac{a - kb}{c} \right \rfloor =
\frac{t+1}{c} \left \lbrace a - \frac{tb}{2}  \right \rbrace
- \frac{1}{c} \left \lfloor \frac{t+1}{u} \right \rfloor
\left \lbrace \frac{u(c-d)}{2} + \lambda u \right \rbrace - \frac{r}{c} . $$
For example, with $a=1019,b=33$ and $c=55$ we have $d=\text{gcd}(33,55)=11,$
$u=c/d=55/11=5,$ $t= \lfloor 1019/33 \rfloor = 30$  and $ 1019 \equiv 29 \textrm{ mod } 55, $ and
$ 1019 \equiv 7 \textrm{ mod } 11. $ Hence $ r = 29 $ and $\lambda = 7.$
Note that the condition $ u \, | \, t $ is satisfied, and so theorem 2 gives
$$ \sum_{k=0}^{30} \left \lfloor \frac{1019 - 33k}{55} \right \rfloor = 
\frac{31}{55} \left \lbrace 1019 - \frac{ 30 \cdot 33}{2} \right \rbrace
- \frac{6}{55} \left \lbrace \frac{5(55-11)}{2} + 7 \cdot 5 \right \rbrace - \frac{29}{55} = 279.$$
This is easily verified with WolframAlpha, or similar.
Both of these theorems are special cases ($ \mu=0$ and $\mu=1$) of the general result:
Theorem 3: Along with the previous definitions in theorems 1 and 2, let
$ t+1 \equiv \mu \textrm{ mod } u,$ where $ 0 \le \mu < u $ then
$$ \sum_{k=0}^{t} \left \lfloor \frac{a - kb}{c} \right \rfloor =
\frac{t+1}{c} \left \lbrace a - \frac{tb}{2}  \right \rbrace
- \frac{1}{c} \left \lfloor \frac{t+1}{u} \right \rfloor
\left \lbrace \frac{u(c-d)}{2} + \lambda u \right \rbrace $$
$$ - \frac{1}{c} \sum_{k=0}^{\mu - 1} \left \lbrace
r+k \left \lbrace \left( \left \lfloor \frac{b}{c} \right \rfloor + 1 \right) c - b
\right \rbrace \textrm{ mod } c \right \rbrace .$$
There are $ \mu $ terms in the last sum, so this is understood to be zero when $ \mu =0.$ The terms in the final summation of the equation are all $ \ge 0 $ and reduced modulo $c.$
A sketch of the proof runs as follows. On adding up the $t+1$ equations at the start of my previous answer, we add up $ \lfloor (t+1)/u \rfloor $ “complete” sets of residues modulo $c$
(not to be confused with a complete residue system modulo $c$) that are congruent to $ \lambda $ modulo $c.$ The term $ \sum_{k=0}^{\mu - 1} \lbrace r+k \lbrace \cdots \rbrace
\textrm{ mod } c \rbrace $ (equivalent, of course, to $ \sum_{k=0}^{\mu - 1} \lbrace (r-kb) \textrm{ mod } c \rbrace $ ) is the sum of the “left over residues.”
Rearranging the equation obtained from the summation proves the theorem.
Note: In the text $ \lbrace \cdot \rbrace $ is only used for readability and does not indicate fractional part (I find doubled-up curved brackets awkward to read).
Just for fun, here is what we get when we put $ \mu = 2 $ into theorem 3.
Theorem 2(b): Along with the previous definitions, since $ \mu = 2 $ our condition here is that $ u \, | \, (t-1) .$ Now for $ r \ge b $ we obtain
$$ \sum_{k=0}^{t} \left \lfloor \frac{a - kb}{c} \right \rfloor =
\frac{t+1}{c} \left \lbrace a - \frac{tb}{2}  \right \rbrace
- \frac{1}{c} \left \lfloor \frac{t+1}{u} \right \rfloor
\left \lbrace \frac{u(c-d)}{2} + \lambda u \right \rbrace - \frac{2r-b}{c} . \quad (1) $$
For example, with $a=1037,b=33$ and $c=55$ we have $d=\text{gcd}(33,55)=11,$
$u=c/d=55/11=5,$ $t= \lfloor 1037/33 \rfloor = 31$  and $ 1037 \equiv 47 \textrm{ mod } 55, $ and
$ 1037 \equiv 3 \textrm{ mod } 11. $ Hence $ r = 47 $ and $\lambda = 3.$
Note that the condition $ u \, | \, (t-1) $ is satisfied, and so theorem 2(b) gives
$$ \sum_{k=0}^{31} \left \lfloor \frac{1037 - 33k}{55} \right \rfloor = 
\frac{32}{55} \left \lbrace 1037 - \frac{ 31 \cdot 33}{2} \right \rbrace
- \frac{6}{55} \left \lbrace \frac{5(55-11)}{2} + 3 \cdot 5 \right \rbrace - \frac{2 \cdot 47 - 33}{55} = 291.$$
This is easily verified with WolframAlpha, or similar.
For $ r < b $ the final term in $(1)$ would be $ - \frac{2r+c-b}{c}.$
(To be continued... time and enthusiasm permitting :-) )