Can we find a pair with given sum and product?

34 Views Asked by At

Can we find a pair with given sum and product?

for eg if sum = 5 and product = 6 then the pair will be (2,3)

Is there a efficient way to do this?

1

There are 1 best solutions below

0
On BEST ANSWER

It has been known since the Babylonians (with other notations!) that the numbers with given sum $s$ and product $p$ are the roots of the quadratic equation $$x^2-sx+p=0$$ if the equation has real roots, i.e. if $s^2\ge 4p$.