Stirling Number
Time limit9sMemory limit256 MB
Given n, l, r, and a prime p, compute the sum of unsigned Stirling numbers of the first kind [n, k] for k from l to r, modulo p.
- Level
Hard8 of 10
- Topics
- Number theory, Combinatorics, Divide and conquer
- Solved
- No attempts yet
Problem
The Stirling number of the first kind is the number of permutations of elements with exactly disjoint cycles. The well-known recurrence is
for , with the initial conditions
for .
Given four integers , , , and , find the value of
where is prime.
Input
The first line contains four integers , , , and (, , , is prime).
Output
Output an integer denoting the answer.