QOJ.ac

QOJ

시간 제한: 4.0 s 메모리 제한: 1024 MB 총점: 100 해킹 가능 ✓

#14410. 丛林与金字塔

통계

爱丽丝在丛林中探索神秘建筑以寻找宝藏,她发现了一座由玛雅祭司建造的金字塔。爱丽丝进入金字塔后,发现自己置身于一条走廊中,走廊里排着一排共 $n$ 个房间的入口。经过调查,她发现这些房间被唯一地标记为 $1$ 到 $n$ 的编号,但在进入房间之前,每个房间的具体编号是未知的。她还发现宝藏藏在编号为 $k$ 的房间里。

考虑到自己剩余的体力,爱丽丝很难逐个检查所有房间。然而,爱丽丝有一个应对这种情况的秘密策略:二分查找。爱丽丝此前曾成功地将二分查找应用于各种挑战。用尽最后的力气,她决定使用二分查找来寻找编号为 $k$ 的房间。

具体来说,爱丽丝的操作步骤如下。首先,她将变量 $\ell$ 和 $r$ 分别初始化为 $\ell = 0$ 和 $r = n + 1$。然后,她重复以下步骤 1 到 3:

  1. 如果 $\ell + 1 = r$,停止搜索,因为她没有找到编号为 $k$ 的房间。
  2. 令 $m = \lfloor (\ell + r)/2 \rfloor$。 进入从左往右数第 $m$ 个房间,检查其编号,记该编号为 $x$。
  3. 如果 $x = k$,停止搜索,因为她已经找到了编号为 $k$ 的房间。 如果 $x < k$,将 $\ell$ 更新为 $m$。 如果 $x > k$,将 $r$ 更新为 $m$。

房间和编号之间共有 $n!$ 种可能的映射方式。你需要求出,在多少种可能的映射方式下,爱丽丝能够使用上述步骤成功找到编号为 $k$ 的房间。答案对 $998\,244\,353$ 取模。

给定 $t$ 组测试数据,计算每组数据的答案。

输入格式

输入的第一行包含一个整数 $t$,表示测试数据的组数($1 \le t \le 10^5$)。接下来是 $t$ 组测试数据。

每组测试数据占一行,包含两个整数 $n$ 和 $k$($3 \le n \le 10^6$,$1 \le k \le n$)。

输出格式

对于每组测试数据,输出一个整数,表示该测试数据的答案。

样例

输入样例 1

5
3 1
4 2
5 4
10 5
1000000 314159

输出样例 1

4
12
66
1192320
853363991

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.