If we write down the first few terms of this sum we notice a pattern.
For 1 to 3 GIF will be 1 ,
For 4 to 8 GIF will be 2 ,
For 9 to 15 GIF will be 3 ,
For 16 to 24 GIF will be 4
It starts (1 +1+1) + (2 + 2 + 2 +2 + 2) + (3 + 3 + 3 + 3 + 3 + 3 + 3) + · · ·. There are three l's, then five 2's, then seven 3's, and so on;
In general there are $(i+1)^{2} - i^{2}$ = 2i + 1 copies of i. So we need to sum i(2i + 1) for an appropriate range of values for i.
We must find this range. It gets a little messy at the end if m is such that the sequence stops before a complete range of the last value is present. Let n = floor(√m) - 1. Then there are n + 1 blocks, and $(n+1)^{2}$ - 1 is where the next-to-last block ends.
The sum of those complete blocks is
$\sum_{i=1}^{n}$ i(2i + 1) = $\sum_{i=1}^{n}$ 2$i^{2}$ + i = n(n + 1)(2n + 1)/3 + n(n + 1)/2.
The remaining terms in our summation all have the value n + 1 and the number of them present is m - ($(n + 1)^{2}$ - 1).
Our final answer is therefore
n(n + 1)(2n + 1)/3 + n(n + 1)/2 + (n + 1)(m - $(n + 1)^{2}$ + 1).