Squares Ending in n Occurrences of m-Digit Pattern/Example

Example of Squares Ending in n Occurrences of m-Digit Pattern
The $n$th term in the sequence:
 * $611, 734 \, 611, 494 \, 734 \, 611, 63 \, 494 \, 734 \, 611, \dots$

have squares ending in $n$ occurrences of $321$:

Proof
First we note that $611^2 = 373 \, 321 \equiv 1 \, 321 \pmod {2 \, 000}$.

Hence the condition in the theorem is satisfied.

Now we construct the sequence using the Induction Step as an algorithm:

For $n = 2$, we find $b < 1 \, 000$ such that:
 * $611 b \equiv \dfrac {321 - 1} 2 - \dfrac {373 \, 321 - 1 \, 321} {2 \, 000} \equiv -26 \pmod {10^3}$

we have $b = 234$.

However:
 * $234 \, 611^2 = 55 \, 042 \, 321 \, 321 \equiv 0 \, 321 \, 321 \pmod {2 \times 10^6}$

So we need to take $b' = 234 + 500 = 734$.

We see that:
 * $734 \, 611^2 = 539 \, 653 \, 321 \, 321 \equiv 1 \, 321 \, 321 \pmod {2 \times 10^6}$

For $n = 3$, we find $b < 1 \, 000$ such that:
 * $734 \, 611 b \equiv \dfrac {321 - 1} 2 - \dfrac {539 \, 653 \, 321 \, 321 - 1, 321 \, 321} {2 \, 000 \, 000} \equiv -269 \, 666 \pmod {10^3}$

That is:
 * $611 b \equiv 334 \pmod {10^3}$

we have $b = 994$.

However:
 * $994 \, 734 \, 611^2 = 989 \, 496 \, 946 \, 321 \, 321 \, 321 \equiv 0 \, 321 \, 321 \, 321 \pmod {2 \times 10^9}$

So we need to take $b' = 994 - 500 = 494$.

We see that:
 * $494 \, 734 \, 611^2 = 244 \, 762 \, 335 \, 321 \, 321 \, 321 \equiv 1 \, 321 \, 321 \, 321 \pmod {2 \times 10^9}$

For $n = 4$, we find $b < 1 \, 000$ such that:
 * $494 \, 734 \, 611 b \equiv \dfrac {321 - 1} 2 - \dfrac {244 \, 762 \, 335 \, 321 \, 321 \, 321 - 1, 321 \, 321 \, 321} {2 \, 000 \, 000 \, 000} \equiv -122 \, 381 \, 007 \pmod {10^3}$

That is:
 * $611 b \equiv -7 \pmod {10^3}$

we have $b = 563$.

However:
 * $563 \, 494 \, 734 \, 611^2 = 317 \, 526 \, 315 \, 934 \, 321 \, 321 \, 321 \, 321 \equiv 0 \, 321 \, 321 \, 321 \, 321 \pmod {2 \times 10^{12}}$

So we need to take $b' = 563 - 500 = 63$.

We see that:
 * $63 \, 494 \, 734 \, 611^2 = 4 \, 031 \, 581 \, 323 \, 321 \, 321 \, 321 \, 321 \equiv 1 \, 321 \, 321 \, 321 \, 321 \pmod {2 \times 10^9}$

The sequence can be continued.