I'm looking for a mathematical method to find an integer X if I multiplied by N and add one on the result will get a perfect square value. $$X * N + 1 = (Perfect Square)$$ I need all X values under N
Example:
$N = 72311$
I found X can be:
$7650 , 33109, 72309$
$7560 * 72311 + 1 = 23381^2$
$33109 * 72311 + 1 = 48930^2$
$72309 * 72311 + 1 = 72310^2$
I programmed a small application in PHP as brute force application to find all X values less than N, but if N was very big more than 15 digit, it takes a long long time to give me the answer.
<?php
$n = 72311;
$N = gmp_init($n);
for($i = 2; $i < $n; $i++)
{
$x= gmp_add(gmp_mul($N, $i), 1);
if(gmp_perfect_square($x))
echo $i."\n";
}
?>
So could you help me in a mathematical method to give me the answer without using a brute force method ?
Thanks in advanced
Update :
I have found something may be useful to find a solution to this problem.
I have used multiplicative modular inverse with the square roots and it equals itself!
$$\sqrt{PerfectSquare}^{-1}\mod N = \sqrt{PerfectSquare}$$
Apply on previous example:
$23381^{-1}\mod 72311 = 23381$
$48930^{-1}\mod 72311 = 48930$
$72310^{-1}\mod 72311 = 72310$
So I will add another question to my first question.
How can I find these values instead of searching about X values ?