52
N2. Each positive integer a undergoes the following procedure in order to obtain the num-
ber d = d(a):
(i) move the last digit of a to the first position to obtain the number b;
(ii) square b to obtain the number c;
(iii) move the first digit of c to the end to obtain the number d.
(All the numbers in the problem are considered to be represented in base 10.) For example,
for a = 2003, we get b = 3200, c = 10240000, and d = 02400001 = 2400001 = d(2003).
Find all numbers a for which d(a) = a
2
.
Solution. Let a be a positive integer for which the procedure yields d = d(a) = a
2
. Further
assume that a has n + 1 digits, n ≥ 0.
Let s be the last digit of a and f the first digit of c. Since (∗···∗s)
2
= a
2
= d = ∗···∗f
and (s ∗···∗)
2
= b
2
= c = f ∗···∗, where the stars represent digits that are unimportant at
the moment, f is both the last digit of the square of a number that ends in s and the first
digit of the square of a number that starts in s.
The square a
2
= d must have either 2n + 1 or 2n + 2 digits. If s = 0, then n 6= 0, b has n
digits, its square c has at most 2n digits, and so does d, a contradiction. Thus the last digit
of a is not 0.
Consider now, for example, the case s = 4. Then f must be 6, but this is impossible,
since the squares of numbers that start in 4 can only start in 1 or 2, which is easily seen
from
160 ···0 = (40 ···0)
2
≤ (4 ∗ ···∗)
2
< (50 ···0)
2
= 250 ···0.
Thus s cannot be 4.
The following table gives all possibilities:
s 1 2 3 4 5 6 7 8 9
f = last digit of (···s)
2
1 4 9 6 5 6 9 4 1
f = first digit of (s ···)
2
1, 2, 3 4, 5, 6, 7, 8 9, 1 1, 2 2, 3 3, 4 4, 5, 6 6, 7, 8 8, 9
Thus s = 1, s = 2, or s = 3 and in each case f = s
2
. When s is 1 or 2, the square c = b
2
of
the (n + 1)-digit number b which starts in s has 2n + 1 digits. Moreover, when s = 3, the
square c = b
2
either has 2n + 1 digits and starts in 9 or has 2n + 2 digits and starts in 1.
However the latter is impossible since f = s
2
= 9. Thus c must have 2n + 1 digits.
Let a = 10x + s, where x is an n -digit number (in case x = 0 we set n = 0). Then
b = 10
n
s + x,
c = 10
2n
s
2
+ 2 · 10
n
sx + x
2
,
d = 10(c − 10
m−1
f) + f = 10
2n+1
s
2
+ 20 · 10
n
sx + 10x
2
− 10
m
f + f,
where m is the number of digits of c. However, we already know that m must be 2n + 1 and
f = s
2
, so
d = 20 · 10
n
sx + 10x
2
+ s
2