When the average will change

average

I have a random number (eg 455,835). Starting from 615 downwards I would like to calculate when the two integers average changing.

For example. I know that 603 and 755's average is 679. How can I calculate it with an equation that the next change will happen at 598?

I can only work with natural numbers. Rational numbers are not allowed.

Edit:
Clarification from eyeballfrog:

So the idea is you have some arbitrary number N choose various x<N.
You calculate another number y=⌊N/x⌋, then take the truncated average
⌊(x+y)/2⌋, and want to know when that average changes.

Sample

enter image description here

Best Answer

The properties of flooring allow us to simplify the expression to $$ \left\lfloor \frac{ x + N/x}{2}\right\rfloor $$ We can also tell that the value will change between $x$ and $x + 1$ if there is a real number $y$, $x < y < x+1$ such that $(y + N/y)/2$ is an integer. Calling this integer $k$, we can set $k = (y + N/y) /2$ and solve for $y$ to get $$ x = \lfloor y \rfloor = \lfloor k \pm \sqrt{k^2 - N}\rfloor $$ Applying this formula to the values $[678, 683]$ gives $615, 606, 598, 591, 585, 579$, which lines up perfectly with the spreadsheet.