Logo
(追記) (追記ここまで)

20621번 - Stirling Number 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
9 초 256 MB5211628.571%

문제

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

$$\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 > 0$.

Given four integers, $n,ドル $l,ドル $r,ドル and $p,ドル find the value of $$\left(\sum_{k=l}^{r}{\begin{bmatrix} n \\ k \end{bmatrix}} \right) \bmod p$$ where $p$ is prime.

입력

The first line contains four integers, $n,ドル $l,ドル $r,ドル and $p$ (1ドル \le n \le 10^{18},ドル 0ドル \le l \le r \le n,ドル 2ドル \le p \le 10^6,ドル $p$ is prime).

출력

Output an integer denoting the answer.

제한

예제 입력 1

4 1 4 5

예제 출력 1

4

예제 입력 2

6 5 5 29

예제 출력 2

15

예제 입력 3

1000 685 975 999983

예제 출력 3

482808

힌트

출처

Camp > Petrozavodsk Programming Camp > Summer 2020 > Day 4: Xi Lin Contest 6 I번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /