Stirling Number

아직 제출이 없습니다시간 제한9초메모리 제한256 MB

문제

The Stirling number of the first kind [n k]\begin{bmatrix} n \\\ k \end{bmatrix} is the number of permutations of nn elements with exactly kk disjoint cycles. The well-known recurrence relation is defined as follows: [n+1 k]=n[n k]+[n k1]\begin{bmatrix} n+1 \\\ k \end{bmatrix} = n \begin{bmatrix} n \\\ k \end{bmatrix} + \begin{bmatrix} n \\\ k-1 \end{bmatrix} for k>0k>0, with the initial conditions

[0 0 ]=1and[n 0]=[0 n]=0\begin{bmatrix} 0 \\\ 0 \end{bmatrix} = 1 \quad {\text{and}} \quad \begin{bmatrix} n \\\ 0 \end{bmatrix} = \begin{bmatrix} 0 \\\ n \end{bmatrix} = 0 for n>0n > 0.

Given four integers, nn, ll, rr, and pp, find the value of (_k=lr[n k])modp\left(\sum\_{k=l}^{r}{\begin{bmatrix} n \\\ k \end{bmatrix}} \right) \bmod p where pp is prime.

입력

The first line contains four integers, nn, ll, rr, and pp (1n10181 \le n \le 10^{18}, 0lrn0 \le l \le r \le n, 2p1062 \le p \le 10^6, pp is prime).

출력

Output an integer denoting the answer.