CF2197A.Friendly Numbers

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

Friendly Numbers

For an integer xx, we call another integer yy friendly if the following condition holds:

  • yd(y)=xy - d(y) = x, where d(y)d(y) is the sum of the digits of yy.

For a given integer xx, determine how many friendly numbers it has.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t5001 \le t \le 500). The description of the test cases follows.

Each test case consists of a single line containing one integer xx (1x1091 \le x \le 10^{9}).

Output

For each test case, output one integer — the answer to the problem.

Note

The number 11 does not have any friendly numbers.

The number 1818 has 1010 friendly numbers: These are all the numbers from 2020 to 2929. For example, 20d(20)=202=1820 - d(20) = 20 - 2 = 18.

The number 998244360998\,244\,360 has 1010 friendly numbers:

  • 998244400998\,244\,400
  • 998244401998\,244\,401
  • 998244402998\,244\,402
  • 998244403998\,244\,403
  • 998244404998\,244\,404
  • 998244405998\,244\,405
  • 998244406998\,244\,406
  • 998244407998\,244\,407
  • 998244408998\,244\,408
  • 998244409998\,244\,409

Samples

3
1
18
998244360
0
10
10

在线编程 IDE

建议全屏模式获得最佳体验