#K79872. Minimum Integer with Given Digit Sum
Minimum Integer with Given Digit Sum
Minimum Integer with Given Digit Sum
You are given a positive integer n. Your task is to find the minimum positive integer m such that the sum of its digits equals n. Formally, if m has digits d_1, d_2, \dots, d_k, you need to find the smallest m for which
\(d_1 + d_2 + \cdots + d_k = n\)
For example:
- If n = 10, then m = 19 because \(1+9=10\) and no positive integer smaller than 19 gives a digit sum of 10.
- If n = 27, then m = 999.
It can be shown that the answer always exists.
inputFormat
The input is read from standard input and consists of:
- An integer T representing the number of test cases.
- T lines follow, each containing a single integer n.
outputFormat
For each test case, output the minimum integer m such that the sum of its digits is n. Each result should be printed on a new line to standard output.
## sample3
1
9
10
1
9
19
</p>