0
$\begingroup$

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

$\endgroup$
4
  • $\begingroup$ I am not sure I understand how your list is generated. For in the beginning you take the pair $(615, 741)$ then $(614, 742)$ so the first number ticks down and the second ticks up. The two numbers naturally average to the same constant each time because at the $n$:th iteration you are calculating $\frac{(615-n) + (741+n)}{2}=\frac{615+741}{2}$. But, then you skip $761$ which should be at row $22$? $\endgroup$
    – user649348
    Commented Nov 28, 2021 at 21:15
  • $\begingroup$ Hi. In B:4 you can see the equation how the B column is calculated. Integer division. Column A is just -1 each time. $\endgroup$
    – Klorissz
    Commented Nov 28, 2021 at 21:18
  • 1
    $\begingroup$ So the idea is you have some arbitrary number $N$ choose various $x < N$. You calculate another number $y = \lfloor N/ x\rfloor$, then take the truncated average $\lfloor (x + y)/2\rfloor$, and want to know when that average changes. Do I have this correct? $\endgroup$ Commented Nov 28, 2021 at 21:23
  • $\begingroup$ @eyeballfrog Yes, it is correct. $\endgroup$
    – Klorissz
    Commented Nov 28, 2021 at 21:25

1 Answer 1

2
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ Thank you. It works flawlessly. $\endgroup$
    – Klorissz
    Commented Nov 28, 2021 at 22:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .