An interesting point to notice though...
Let's not care (yet) about how to do that though. Everytime you reach one of your solutions (i.e. finding a and b so that for the 2 integer values of
x the equation = 0), we can notice that the two roots (x1 and x2) multplied give b.
Similarly, we can notice that a is x1+x2...
Examples with your examples:
- a=225, b=3150 gives x1=15 and x2=210. x1*x2 = 15*210 = 3150, x1+x2 = 225
- starting with 23 and 1866, we have a=167 and b=1860, x1=12 and x2=155, and 12*155=1860 and 12+155 = 167
It seems to work everytime.
Thus the problem can be reduced into finding the closest number lower than the starting b that can be composed in the form of a product.
So...
- We look for b, by decreasing the starting b (b0) of 1 unit everytime.
- For each new b, find the highest divider d (there are many algorithms for that)
- b/d gives x1
- a = x1+d
- we can remark that d = x2 everytime as well...
- test that x1²-ax1+b = 0 (can be evaluated quickly too)
- if no, discard and go on searching for the next d.
- until d<=int(b/5) (it's been tested already that b isn't divisible by 2, 3 and 5)
Now, how to find the greatest divisor of a number?
One of the quickest ways is to start testing "manually", i.e., try to divide by 2, 3, 5 and each time see if it is an integer result or not. If so,
you have your highest divisor. If not, start counting down from int(b/5) and test each time. This reduces the number of iterations to a fairly
reasonable amount.
I agree that this is still a painful complexity... but I don't see any other way...
Besides... It would be nice to know why exactly you specifically build a(next)=a+24 and b(next)=b-1. You surely have your reasons...
[edit on 28-10-2009 by SpookyVince]






) of my method and also of the effect this may potentially have
on encryption systems that rely on primes. 