Given four positive integers
,
,
and
, is there a way to quickly find any two integers
and
such that:
When
and
, there is a closed-form
solution to this using quadratic equations. We simply have to find the roots of
and it will give us a suitable
.
When
, I know how to solve it in
by noticing that the curve
is convex and so we can just binary search for a suitable
.
When
, it can be solved in
by factoring
and looking for a pair of factors that sum to a value within the range.
When both of them are ranges, however, I can't think of any algorithm that can solve this efficiently. There are some possible heuristics, like fixing one of the two (iterating through the smaller range, etc.), or immediately reporting that no pair exists when the largest possible product that can be made with two integers summing to
is smaller than
, etc.
Unfortunately, I haven't been able to come up with anything that would work in the general case that is faster than iterating through everything in either
or
(possibly with some extra smaller factors). Is there a nice algorithm, or some fancy mathematics, that gives a faster solution?
Alternatively, is there a way to prove that iterating terminates quickly? (After handling some corner cases, etc.) I'm not interested in the number of valid pairs; finding any pair will do. It seems that iterating over the product and trying to find a corresponding sum tends to quickly find a solution if the range of allowable sums is sufficiently large. Could there be some sort of proof of this?
I would greatly appreciate any help!

