I am trying to solve the following equation:
n*const1 + const2 = x^2
Where n, const1, const2 and x are integers > 0. Const1, const2 are known, n and x are variables.
The naive solution to this problem is to iterate all n's and check if the square root of the result is integer. This solution is however too slow:
for n = 0;; n++:
if sqrt(n*const1 + const2) is integer:
end.
else:
continue.
Would it help, if the const1 was a prime number?
x^2byconst1and see if the remainder is equal toconst2? (You need to reduceconst2in some way before to guaranteeconst2is between0andconst1 - 1. I thinkconst2 := const2 mod const1should work.) – Tunococ Aug 14 '12 at 21:56