I'm trying to find the maximum of the sum $$\sum_{i=1}^n \frac{i}{(\lceil \frac{i}{r} \rceil + 1)r}$$ where $\frac {n}{M} \leq r\leq 1 $ and $n\leq M$ and M is a known integer.
Since the fraction is a piece-wise continuous function and descending in those continuous ranges, I only need to find points where ceil function makes a step, and then compare those points with each other. To compare these points I need to calculate the sum for all $r$ where $\frac {i}{r} $ is an integer and $i \in \{1,....,n\}$.
There are too many points with the mentioned situation, so I was wondering if there is a way to find the maximum of the sum without calculating it for all points of discontinuity.