問題一覧 > 通常問題

No.645 Count Permutation

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 24
作問者 : Pulmn / テスター : yosupot
お気に入りにしたユーザー ProblemId : 1864 / 自分の提出
問題文最終更新日: 2026-06-28 13:25:46
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 182 (順位表) の他の問題:

Problem Statement

Find the number of permutations $A$ of $(1,2,\dots ,N)$ that satisfy the following condition. Since this value can be very large, output it modulo $1{,}000{,}000{,}007$.

Condition: The number of permutations $B$ of $(1,2,\dots ,N)$ satisfying $f(B)=A$ is at least $L$ and at most $R$. Here, $f(B)$ is the permutation obtained by performing the following operation on $B$.

Operation: In the order $i=1,2,\dots ,N-1$, if $B_i\gt B_{i+1}$, swap the values of $B_i$ and $B_{i+1}$.

Input

$N$ $L$ $R$

$2\le N\le 10^5,0\le L\le R\le 10^{18}$

Output

Output the number of permutations $A$ satisfying the condition, modulo $1{,}000{,}000{,}007$. Print a newline at the end.

Sample

Sample 1
Input
5 2 7
Output
17

Let us perform the above operation with $B=\{2,4,1,3,5\}$.
For $i=1$, $B_i \lt B_{i+1}$, so nothing is done.
For $i=2$, $B_i \gt B_{i+1}$, so $B=\{2,1,4,3,5\}$.
For $i=3$, $B_i \gt B_{i+1}$, so $B=\{2,1,3,4,5\}$.
For $i=4$, $B_i \lt B_{i+1}$, so nothing is done.
Therefore, $f(\{2,4,1,3,5\})=\{2,1,3,4,5\}$.
Examples of permutations $A$ satisfying the condition include $A=\{3,4,2,1,5\},\{4,2,3,1,5\}$.

Sample 2
Input
10 0 3628800
Output
3628800

Since $10!=3628800$, all permutations of $(1,2,\dots ,10)$ satisfy the condition as $A$.

Sample 3
Input
1000 1000 1000
Output
0

The value to output may be $0$.

Sample 4
Input
100 1000000000 1000000000000000000
Output
2041684

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。