Let $m$ be a strictly positive integer, and let $r_{1}, \ldots r_{m}$ be rational numbers such that $r_{1}+\ldots+r_{m}=1$. What are the minimum and maximum values attained by the function $f(n)=n-\sum_{i=1}^{m}\left[r_{i} n\right]$ for $n \in \mathbb{N}^{*}$?
Let's start by framing $f(n)$ to get an idea of the extremes: for all $i, r_{i} n-1<\left[r_{i} n\right] \leqslant r_{i} n$, hence $n-m<\sum_{i=1}^{m} r_{i} n \leqslant n$, hence $0 \leqslant f(n) \leqslant m-1$. We will show that in fact the values 0 and $m-1$ are reached. Let $A$ be a common denominator for all the $r_{i}$ (we can have the idea to consider it because it realizes the equality in the very first inequality written), then since $r_{i} A$ is an integer for all $i, f(A)=0$. On the other hand, $f(A-1)=$ $A-1-\sum_{i=1}^{m}\left[r_{i}(A-1)\right]=A-1-\sum_{i=1}^{m}\left(r_{i} A-1\right)=m-1$.