๐Ÿงฎ Brain Teaser

A Sequence That Always Hits a Perfect Square

Define a sequence (ak)k=0โˆž(a_k)_{k=0}^{\infty} as follows. Let S(n)=nโˆ’m2S(n) = n - m^2, where mm is the greatest integer with m2โ‰คnm^2 \leq n. (So S(n)S(n) is the "remainder" when you subtract the largest perfect square โ‰คn\leq n.)

Set a0=Aa_0 = A (a positive integer), and

ak+1=ak+S(ak),kโ‰ฅ0.a_{k+1} = a_k + S(a_k), \quad k \geq 0.

For which positive integers AA does this sequence eventually become constant?

(The sequence is constant once it reaches some value and stays there forever.)

sequencesperfect squaresnumber theoryfixed pointsparity argument

Answer: A Sequence That Always Hits a Perfect Square

Key Idea / Intuition

The sequence is constant exactly when it hits a perfect square โ€” because if ak=m2a_k = m^2, then S(ak)=0S(a_k) = 0, so ak+1=aka_{k+1} = a_k. The question is: starting from AA, does the sequence always reach a perfect square, or can it wander forever?

The key insight is to track what happens modulo small numbers, or more cleverly, to notice that perfect squares are the only fixed points, and the sequence is non-decreasing. Once you see that S(n)=0โ€…โ€ŠโŸบโ€…โ€ŠnS(n) = 0 \iff n is a perfect square, the question becomes: does every starting integer eventually land on a perfect square?

The answer is: the sequence eventually becomes constant if and only if AA is a perfect square, because for non-square AA, the sequence strictly increases and โ€” surprisingly โ€” skips over every perfect square it approaches.


Formal Proof / Solution

Step 1: Fixed points are exactly perfect squares.

If n=m2n = m^2, then S(n)=nโˆ’m2=0S(n) = n - m^2 = 0, so the sequence is constant. If nn is not a perfect square, S(n)โ‰ฅ1S(n) \geq 1, so the sequence strictly increases.

Step 2: What happens near a perfect square?

Suppose n=m2โˆ’jn = m^2 - j for some 1โ‰คjโ‰ค2mโˆ’11 \leq j \leq 2m - 1 (i.e., nn lies just below m2m^2). The largest perfect square โ‰คn\leq n is (mโˆ’1)2(m-1)^2, so:

S(n)=nโˆ’(mโˆ’1)2=m2โˆ’jโˆ’(mโˆ’1)2=2mโˆ’1โˆ’j.S(n) = n - (m-1)^2 = m^2 - j - (m-1)^2 = 2m - 1 - j.

Therefore:

ak+1=n+S(n)=m2โˆ’j+2mโˆ’1โˆ’j=m2+(2mโˆ’1โˆ’2j).a_{k+1} = n + S(n) = m^2 - j + 2m - 1 - j = m^2 + (2m - 1 - 2j).

Step 3: Does the sequence land on m2m^2?

For the sequence to land exactly on m2m^2, we need 2mโˆ’1โˆ’2j=02m - 1 - 2j = 0, i.e., j=2mโˆ’12j = \frac{2m-1}{2}. But jj must be an integer, and 2mโˆ’12m - 1 is odd, so this is impossible!

This is the key surprise: the sequence always jumps over m2m^2 entirely โ€” landing either below or strictly above m2m^2.

Step 4: Conclusion.

If AA is a perfect square, the sequence is immediately constant. If AA is not a perfect square, then the sequence is strictly increasing and never lands on any perfect square (since by Step 3, you always overshoot). Therefore, the sequence grows without bound and is never constant.

Hence the sequence eventually becomes constant if and only if AA is a perfect square.

Example verification: Start at A=7A = 7.

  • m=2m = 2 (since 22=4โ‰ค7<9=322^2 = 4 \leq 7 < 9 = 3^2), S(7)=7โˆ’4=3S(7) = 7 - 4 = 3, so a1=10a_1 = 10.
  • m=3m = 3 (since 9โ‰ค10<169 \leq 10 < 16), S(10)=10โˆ’9=1S(10) = 10 - 9 = 1, so a2=11a_2 = 11.
  • m=3m = 3, S(11)=2S(11) = 2, so a3=13a_3 = 13.
  • m=3m = 3, S(13)=4S(13) = 4, so a4=17a_4 = 17.
  • And so on โ€” it keeps jumping past every perfect square (skipping 16, 25, ...).

Compare with A=9A = 9: S(9)=0S(9) = 0, so it's immediately constant. โœ“

Source: Putnam 1991, Problem B-1

Type: PutnamSource: Putnam 1991, Problem B-1Edit on GitHub โ†—