$O(k)$ Algorithm to find the first $k$ pairs of Magic numbers $a$ and $b$ such that $\sum_{i=1}^{a-1} i = \sum_{k=a+1}^b k $, with restrictions
There are different ways you can use to solve that problem.

One simple but inefficient solution is just that of just computing the two sums in parallel while only keeping track of the difference between their partial sums. I.e., if you added the first $x$ terms of the first sum and first $y$ terms of the second sum, then you'll only remember $x$, $y$, and $\Delta = \sum_{i=1}^x i - \sum_{k=a+1}^{a+1+y} k$.  If $\Delta$ is non-positive, then consider the next term of the first sum (i.e., increment $x$ by one and add $x$ to $\Delta$). If $\Delta$ is positive, then consider the next term of the second sum (i.e., increment $y$ by one and subtract $a+1+y$ from $\Delta$). In this way $|\Delta|$ will never exceed $\max\{a,b\}$.



Another more efficient solution is as follows. Using the summation formula you can write:
$
\sum_{i=1}^{a-1} i = \frac{a(a-1)}{2} = \frac{b(b+1)}{2} - \frac{a(a+1)}{2}
= \sum_{k=a+1}^{b} k$, and some simplifications lead to:
$2a^2 = b(b+1)$.

This means that, once you fix $b$, you can find the corresponding value of $a$ as follows:
$$
a= \frac{1}{\sqrt{2}} \cdot \sqrt{b} \cdot \sqrt{b+1}.
$$

Notice that $\sqrt{b} \cdot \sqrt{b+1}$ must always be greater than $b$ and smaller than $b+1$, meaning that  $\frac{b}{\sqrt{2}} &lt; a &lt; \frac{b}{\sqrt{2}} + \frac{1}{\sqrt{2}}$ and, since $\frac{1}{\sqrt{2}} &lt; 1$, there is at most one integer in that interval, namely $ 1+  \left\lfloor \frac{b}{\sqrt{2}} \right\rfloor = 1+  \left\lfloor \frac{\sqrt{2} b}{2} \right\rfloor $.