The square of a number's last few digits remain the same.

It suffices to find the solutions to $x^2 \equiv x \mod 16$ and $x^2 \equiv x \mod 625$. As these polynomials are degree two and we're looking at solutions mod prime powers, there are at most two solutions to each by Hensel's lemma. Each has only the solutions $x \equiv 0, 1$. These extend via CRT to solutions $0, 1, 625, 9376$.

The OEIS lists a sequence of least $n$-digit integers such that $a_n^2$ ends in $a_n$.

EDIT: Ross Millikan, in the comments below, notes that the CRT solution given here gives us two non-trivial (not $0$ and not $1$) such integers for each $n$. Let $x$ be one of them and $y$ be the other. Then one is $0$ mod $2^n$ and the other is $0$ mod $5^n$; their product is $0$ mod $10^n$. So $(x+y)^2 = x^2 + 2xy + y^2 \equiv x^2 + y^2 \equiv x+y \mod 10^n$; this gives us another solution to $x^2 \equiv x$ that is not divisible by $2$; so it is $1$. Thus $x+y \equiv 1 \mod 10^n$. This, along with the fact that neither $x$ nor $y$ are $1$, proves that there exists such an integer of length $n$ for all $n$.


It seems that http://oeis.org/A094190 doesn't provide complete list of such numbers. Complete list (without leading zeros is here: http://oeis.org/A003226).

If not consider trivial $0$ and $1$, then for each $n$ there are $2$ $n$-digital such numbers, that last $n$ digits of their square are the same that number (sometimes solution has leading zeroes):

$$ \begin{array}{|l|rr|rr|} \hline \\ n & A & A^2 & B & B^2 \\ \hline \\ 1) & 5^2= & 2\color{red}{\bf 5} & 6^2= & 3\color{red}{\bf 6} \\ 2) & 25^2= & 6\color{red}{\bf{25}} & 76^2= & 57\color{red}{\bf{76}} \\ 3) & 625^2= & 390\color{red}{\bf{625}} & 376^2= & 141\color{red}{\bf{376}} \\ 4) & 0625^2= & 39\color{red}{\bf{0625}} & 9376^2= & 8790\color{red}{\bf{9376}} \\ 5) & 90625^2= & 82128\color{red}{\bf{90625}} & 09376^2= & 879\color{red}{\bf{09376}} \\ 6) & 890625^2= & 793212\color{red}{\bf{890625}} & 109376^2= & 11963\color{red}{\bf{109376}} \\ 7) & 2890625^2= & 835571\color{red}{\bf{2890625}} & 7109376^2= & 5054322\color{red}{\bf{7109376}} \\ ... & ... & ... & ... & ... \end{array} $$

Easy way to construct:

If $n$-digital number $A = \overline{a_{n-1}...a_2a_15}$, and $A^2 = \overline{...q_n \color{red}{a_{n-1}...a_2a_1 5 }}$, then first digit of next such $(n+1)$-digital number $A$ is $a_n=q_n$.

If $n$-digital number $B = \overline{b_{n-1}...b_2 b_1 6}$, and $B^2 = \overline{...r_n \color{red}{b_{n-1}...b_2 b_1 6}}$, then first digit of next such $(n+1)$-digital number $B$ is $b_n=10-q_n (\mod ~10)$.

Example: if $109376^2 = ...3\color{red}{109376}$, then first digit of next ($7$-digital) such number is $10-3 (\mod ~10) = 7$, so next number in "$B$-sequence" is $7109376$.


Just for curiosity:

$...580863811000557423423230896109004106619977392256259918212890625^2$

$...419136188999442576576769103890995893380022607743740081787109376^2$

Tags:

Contest Math