#K74382. Counting N-Digit Numbers with a Given Digit Sum

    ID: 34185 Type: Default 1000ms 256MiB

Counting N-Digit Numbers with a Given Digit Sum

Counting N-Digit Numbers with a Given Digit Sum

Given two integers \(n\) and \(S\), count the number of \(n\)-digit numbers such that the sum of their digits equals \(S\).

Note that numbers with more than one digit cannot have a leading zero. In other words, if \(n>1\), the first digit must be non-zero. However, when \(n=1\), the digit 0 is allowed.

For example, when \(n=2\) and \(S=5\), there are 5 valid numbers, and when \(n=3\) and \(S=6\), there are 21 valid numbers.

The input consists of multiple lines. Each line contains a pair of integers \(n\) and \(S\). The input terminates with a line containing "0 0", which should not be processed.

inputFormat

The input is read from standard input (stdin) and consists of several lines. Each line contains two integers \(n\) and \(S\), separated by a space.

The input ends with a line "0 0" which should not be processed.

For example:

2 5
3 6
0 0

outputFormat

For each test case (each valid line), output the count of \(n\)-digit numbers whose digits sum to \(S\) on a new line. The output is written to standard output (stdout).

For example, the output for the sample input above is:

5
21
## sample
2 5
3 6
0 0
5

21

</p>