Find $1 \le a < b \le n$ such that $$a\cdot b + a + b = \frac{n\cdot (n+1)}2$$
Is there a more efficient way than picking $a$ or $b$ and trying all values between $1$ and $n$ ?
Find $1 \le a < b \le n$ such that $$a\cdot b + a + b = \frac{n\cdot (n+1)}2$$
Is there a more efficient way than picking $a$ or $b$ and trying all values between $1$ and $n$ ?
Copyright © 2021 JogjaFile Inc.
$(a+1)(b+1)=\dfrac{n^2+n+2}{2}$.
If $a$ and $b$ are restricted to integers, consider the factors of $\dfrac{n^2+n+2}{2}$.