#P6356. Counting Numbers with Given Digit Sum
Counting Numbers with Given Digit Sum
Counting Numbers with Given Digit Sum
Given three integers A, B, and S, count how many numbers in the interval \([A, B]\) (inclusive) have the sum of their digits equal to \(S\), and also find the smallest such number. The problem is defined as follows:
For a number \(n\), let \(\text{digit_sum}(n)\) be the sum of its decimal digits. We require:
\[ \text{digit_sum}(n)=S \quad \text{and} \quad A \le n \le B. \]Your task is to output two integers: the total count of numbers satisfying the condition, and the smallest number among them. It is guaranteed that there is at least one number meeting the criteria.
inputFormat
The input consists of a single line containing three space-separated integers:
- A and B: the endpoints of the interval (with A ≤ B).
- S: the target sum of digits.
outputFormat
Print two space-separated integers on a single line: the count of numbers in \([A, B]\) whose digit sum equals \(S\), and the smallest such number.
sample
1 100 10
9 19