#P5160. Counting Sequences with Bounded Sum
Counting Sequences with Bounded Sum
Counting Sequences with Bounded Sum
WD once wrote a long nested for-loop to solve a seemingly simple problem. Given two integers (n) and (m), count the number of non-negative integer sequences (a_1, a_2, \dots, a_n) such that (a_1+a_2+\cdots+a_n \le m). The answer is to be output modulo 19491001. Using stars and bars, the number of solutions is given by
[ \binom{m+n}{n} \quad \text{or equivalently} \quad \binom{m+n}{m}, ]
where the binomial coefficient is taken modulo 19491001. Even though the problem looks like it could be solved by simulating nested loops, an efficient combinatorial calculation is required. Have fun solving it!
inputFormat
The input consists of a single line containing two non-negative integers n and m (0 ≤ n, m ≤ 105 typically), where n is the length of the sequence and m is the maximum allowed sum.
outputFormat
Output a single integer, the number of sequences satisfying the condition, modulo 19491001.
sample
1 5
6