QOJ.ac

QOJ

実行時間制限: 1.0 s メモリ制限: 512 MB 満点: 100 ハック可能 ✓

#14543. Count Permutation

統計

Alice 喜欢研究排列。对于一个 $n$ 阶排列 $P = (p_1, p_2, \dots, p_n)$,她定义 $w(P) = |S|$,其中 $S = \{p_i - p_{(i \bmod n)+1} \mid 1 \le i \le n\}$。例如,如果 $P = (2, 4, 5, 3, 1)$,那么 $S = \{2, -1, -2\}$,$w(P) = |S| = 3$。

Alice 希望 $S$ 尽可能简单,因此她想找到所有使得 $w(P)$ 最小的 $n$ 阶排列 $P$(她将这些排列定义为“好排列”)。然而,好排列的数量可能非常多。因此,她写下了三个整数 $m, s, t$,并希望你求出满足 $p_1 = s$ 且 $p_m = t$ 的好排列 $P = (p_1, p_2, \dots, p_n)$ 的数量。

输入格式

仅一行,包含 $4$ 个整数 $n, m, s, t$($3 \le n \le 10^{12}$,$2 \le m \le n$,$1 \le s, t \le n$,$s \ne t$)。

输出格式

输出一行一个整数,表示答案。

样例

输入样例 1

3 2 1 3

输出样例 1

1

输入样例 2

4 3 1 3

输出样例 2

2

说明

一个 $n$ 阶排列是一个长度为 $n$ 的整数序列,且 $\{1, 2, \dots, n\}$ 中的每个元素都恰好出现一次。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.