Programming contests

DEIK Regionális Programozó Csapatverseny, egyetemi kategória, 2025. december 7.

December 7, 2025, 10:30 AM – December 7, 2025, 3:30 PM

digits-3

We perform the following operation on a positive integer: we sort its digits in ascending order — removing any leading zeros — then subtract the product of its digits from that number. For example:
3213210 ⟶ 0112233 ⟶ 112233-36 = 112197
We repeat this process with each resulting number until we get zero:
1231230 ⟶ 112197 ⟶ 111153 ⟶ 111120 ⟶ 11110 ⟶ 1110 ⟶ 110 ⟶ 10 ⟶ 0
How many steps does it take to reach zero? What is the maximum number of steps (MM) for all integers in an interval [L,R](LR)[L, R] (L ≤ R) ?

Input specification

The first line contains TT, the number of test cases. Then TT lines follow, each containing the numbers LkL_k and Rk(k=1,,T)R_k~~(k = 1,\ldots,T).

Output specification

Output TT lines, each containing the required value Mk(k=1,T)M_k~~(k = 1,\ldots T).

Constraints

1T1001\le T \le 100
1Lk1_000_000_000_0001\le L_k \le 1\_000\_000\_000\_000
1Rk1_000_000_000_0001\le R_k \le 1\_000\_000\_000\_000
0RkLk100_000(k=1,,T)0\le R_k-L_k \le 100\_000~~~(k=1,\ldots,T)
Solving smaller subtasks will yield partial points.

Sample input 1

  1. 5
  2. 1 99
  3. 100 9999
  4. 10000 100000
  5. 1231230 1233210
  6. 56875687 56875687
download as text file

Sample output 1

  1. 4
  2. 11
  3. 13
  4. 13
  5. 11
download as text file
University of Debrecen; Faculty of Informatics; v. 09/30/2024