(⇒) Step 1. We use exhaustive case analysis to discuss the leading digit and the last digit of k2. First, since 10n−1≤k<10n, we know 102n−2≤k2<102n, hence k2 has either 2n−1 digits or 2n digits.
If k2 has 2n digits, then by exhaustive enumeration we obtain the following table:
Here the possible leading digit(s) of
k2 are the positive integers lying between
⌊10an−12⌋ and
⌊10(an−1+1)2⌋. From the table above, we see that if
k2 has
2n digits, then
k2 cannot be a palindrome. Hence if
k2 is a palindrome, then
k2 must have
2n−1 digits.
Step 2. For 0≤m<n define cm=∑i=0maiam−i. Then, from the condition that k is a palindrome we know
k2=cn−1⋅10n−1+i=0∑n−2(10i+102n−2−i).
And since k2 is also a palindrome, we may assume there exist integers b0,b1,…,bn−1 between 0 and 9 such that
k2=bn−1⋅10n−1+i=0∑n−2bi(10i+102n−2−i).
We prove the following lemma.
Lemma. Let n be a positive integer, let c0,c1,…,cn−1 be nonnegative integers, and let b0,b1,…,bn−1 be integers between 0 and 9. If
cn−1⋅10n−1+i=0∑n−2(10i+102n−2−i)=bn−1⋅10n−1+i=0∑n−2bi(10i+102n−2−i),(1)
then bi=ci for all 0≤i<n.
Proof of Lemma. We induct on n. When n=1 the claim is obvious. Now assume the claim holds for n−1. Taking both sides of (1) modulo 10 gives
c0≡b0(mod10).
So we may write c0=b0+10t. Since 0≤b0≤9 and c0≥0, we get t≥0, hence c0≥b0.
On the other hand, observing (1) again, we have
c0(1+102n−2)≤LHS=RHS<(b0+1)(1+102n−2),
so c0≤b0. Therefore c0=b0.
Cancelling the term c0(1+102n−2) from both sides of (1) and dividing both sides by 10, we get
cn−1⋅10n−2+i=1∑n−2(10i−1+102n−3−i)=bn−1⋅10n−2+i=1∑n−2bi(10i−1+102n−3−i).(2)
We find that (2) allows us to apply the induction hypothesis to obtain bi=ci for 1≤i<n, which completes the proof by mathematical induction.
Returning to the original proof. By the lemma we know
i=0∑n−1aian−1−i=cn−1=bn−1<10,
and since k is a palindrome we know an−1−i=ai, hence we obtain ∑i=0n−1ai2<10.
(⇐) Again let cm=∑i=0maiam−i. From the condition that k is a palindrome we have
k2=cn−1⋅10n−1+i=0∑n−2ci(10i+102n−2−i).
Here it suffices to prove that cm<10 for m<n. In this way, k2=c0c1⋯cn−2cn−1cn−2⋯c1c0 is a palindrome. For m<n, we have
cm=i=0∑maiam−i≤i=0∑m2ai2+am−i2(by AM-GM)=i=0∑mai2<10.