I am currently programming the quadratic sieve and have several literature books / papers and will take an example out of [1] for my question:
[1] An Introduction to Mathemtaical Cryptography by J. Hoffstein, J. Pipher and H. Silverman.
[2] Prime Numbers by R. Crandall and C. Pomerance.
[3] Smooth numbers and the quadratic sieve by C. Pomerance.
To factorize a number $n$ with the quadratic sieve, we are looking for a product of numbers $x^2-n$ giving a perfect square. The numbers $x^2-n$ has to be B-smooth. We also only look prime numbers where the jacobi symbol is $(\frac{n}{p}) = 1$, so we can solve the equation $a^2 \equiv n\ \textrm{mod}\ p$ for every $p$ with $2 \leq p \leq B$. If $p = 2$ there is only one solution and for $p \gt 2$ there are either no solutions or two soluions. But in our case are always 2 solutions, because $n$ is a quadratic residue for our prime numbers.
I will now come to the point where my problem starts. In [1] and [3] is the sieve step explained to recognize B-smooth numbers in our sequence $x^2 - n$. We are looking for the numbers $x$ where $p\ |\ (x^2- n)$.
The values of $x$ can be found "easily" by the roots of $a^2 \equiv n\ \textrm{mod}\ p$ namely the number $x$ which are congruent to $a_1 \textrm{ mod } p$ or $a_2 \textrm{ mod } p$ ($a_1, a_2$ are the roots of $a^2$).
So, we start with the first number in our sequence $x^2-n$ where $x \equiv a_1 \textrm{ mod } p$ and then every $p$-th entry is divisible by $p$. We start again at some start point of $x^2 -n$ and look for a number $x$ for which $x \equiv a_2 \textrm{ mod } p$ hold.
Now I have tried to this with some example from the book but it will stop getting the correct entry of $x$:
In [1] is the example for the number $N = 9788111$. Also, the first 20 numbers which are 50-smooth are listed with the factorization of $x^2 - n$.
The first $x$ is $x = \Big\lceil\sqrt{N}\Big\rceil = 3129$.
It starts now with:
$3129^2 \equiv 2530 \textrm{ mod } 9788111$
$3130^2 \equiv 8789 \textrm{ mod } 9788111$
$3131^2 \equiv 15050 \textrm{ mod } 9788111$
...
$4394^2 \equiv 9519125 \textrm{ mod } 9788111$
Until this number everything works. My program gives the correct factorization. And if we test it with the prime number $p = 7$ and the roots $a_1 = 2$ and $a_2 = 5$, we see that $3131 \equiv 2 \textrm{ mod } 7$. So, we can divide $15050$ with $7$.
But the next number in the list, which is 50-smooth doesn't hold the procedure:
$4425^2 \equiv 4403 \textrm{ mod } 9788111$ and $4403 = 7 * 17 * 37$
We see, that $4403$ is divisible by $7$. That means that $4425$ has to be congruent to $2 \textrm{ mod } 7$ or $5 \textrm{ mod } 7$. But it's not. That means, that at some point I can't just count $x$ with $p$ to get the next number in the sequence which is divisible by $p$. I think its because that the result of $x^2 - n$ is bigger than $n$ self at some specifically $x$ like $4425$:
$4425^2 - n = 19580625 - 9788111 = 9792514 > 9788111$
So, my question is what is the reason that at some $x$ it doesn't work anymore? What can I do to restart the procedure with counting $x$ with $p$ to recognize the valid spot to divide with $p$.