1999 AIME Problem 5

Attempt Problem 5 of the 1999 AIME below, then check your answer against the professionally curated solution from LIVE by Po-Shen Loh. You can also try the full timed exam, view all 1999 AIME solutions, or check the answer key.

All problems are used with official legal permission of the Mathematical Association of America (MAA).

5.

For any positive integer x,x, let S(x)S(x) be the sum of the digits of x,x, and let T(x)T(x) be ∣S(x+2)−S(x)∣.|S(x + 2) - S(x)|. For example, T(199)T(199) =∣S(201)−S(199)∣= |S(201) - S(199)| =∣3−19∣= |3 - 19| =16.= 16. How many values T(x)T(x) do not exceed 1999?1999?
Answer: 223
Concepts:digitsarithmetic sequencecasework
Small hint:
If adding 22 causes no carrying, T(x)=2.T(x) = 2. Carrying happens only when xx ends in 88 or 9.9.
Big hint:
Track how the digit sum changes when xx ends in a run of nines; the carrying values form an arithmetic progression with common difference 99
Solution:
If the last digit of xx is at most 7,7, adding 22 changes no other digit, so T(x)=2.T(x) = 2. Otherwise there is carrying. If xx ends in the digit 88 preceded by exactly m≥0m \ge 0 nines, then x+2x + 2 replaces …a9⋯9⏟m8\ldots a\underbrace{9 \cdots 9}_{m}8 by …(a+1)0⋯0⏟m0,\ldots (a{+}1)\underbrace{0 \cdots 0}_{m}0, so S(x+2)−S(x)=1−9m−8S(x + 2) - S(x) = 1 - 9m - 8 and T(x)=9m+7.T(x) = 9m + 7. If xx ends in exactly m≥1m \ge 1 nines, then x+2x + 2 replaces …a9⋯9⏟m\ldots a\underbrace{9 \cdots 9}_{m} by …(a+1)0⋯0⏟m−11,\ldots (a{+}1)\underbrace{0 \cdots 0}_{m - 1}1, so S(x+2)−S(x)=2−9mS(x + 2) - S(x) = 2 - 9m and T(x)=9m−2.T(x) = 9m - 2.
Both carrying families give exactly the values 7,16,25,…,7, 16, 25, \ldots, that is, 9j+79j + 7 for j≥0,j \ge 0, and every such value occurs. So the possible values of TT are 22 together with all 9j+7.9j + 7. Requiring 9j+7≤19999j + 7 \le 1999 gives j≤221,j \le 221, which is 222222 values, and T=2T = 2 adds one more, for a total of 223.223.
LIVE by Po-Shen Loh
Programs

LIVE Classes

Self-Paced Classes

Stars

Scholarship

About Us

Who Is Po-Shen Loh?

Email Contact

Newsletter

Jobs

Become a Star

For a more Thought Full world.

© 2026 Expii, Inc.