无限工作AI (CI翻译)
More monkeys!— Exponential Idle
You are in charge of a large scientific project studying an unusual function. To carry it out, you hired $10^{10^{100}}$ students and numbered them with natural numbers from $1$ to $10^{10^{100}}$. The students form a hierarchy:
你负责一个研究奇特函数的大型科学项目。为了完成这项工作,你雇用了 $10^{10^{100}}$ 名学生,并用从 $1$ 到 $10^{10^{100}}$ 的自然数为他们编号。这些学生构成如下层级结构:AI (CI翻译)
- Student
$1$is the main one. - For any
$i \geq 2$, the direct supervisor of student$i$is student$\left\lfloor \frac{i}{2} \right\rfloor$. - The direct subordinates of student
$i$are students$2i$and$2i+1$(if these numbers do not exceed$10^{10^{100}}$). - Subordination is transitive: if
$a$is subordinate to$b$, and$b$is subordinate to$c$, then$a$is subordinate to$c$.
- 学生
$1$是最高负责人。 - 对于任意
$i \geq 2$,学生$i$的直属上级是学生$\left\lfloor \frac{i}{2} \right\rfloor$。 - 学生
$i$的直属下属是学生$2i$和$2i+1$(如果这些编号不超过$10^{10^{100}}$)。 - 下属关系具有传递性:如果
$a$是$b$的下属,且$b$是$c$的下属,那么$a$也是$c$的下属。
Initially, all students are working.
最初,所有学生都在工作。AI (CI翻译)
There are $n$ days left until the project is completed. Each day consists of two stages:
项目还剩 $n$ 天。每天分为两个阶段:AI (CI翻译)
- Hiring. Each working student
$i$hires all the non-working students who are directly subordinate to him: Newly hired students cannot hire anyone on the same day. - If student
$2i$is not working and$2i \leq 10^{10^{100}}$, he starts working.- If student
$2i + 1$is not working and$2i + 1 \leq 10^{10^{100}}$, he starts working.
- If student
- Firing. You may choose any set of working students and directly fire each of them. If student
$i$is directly fired, then all of his subordinates are automatically fired as well. Such firings are called indirect. Student$1$cannot be fired.
- 招聘。 每名正在工作的学生
$i$都会招聘所有不在工作的直属下属:当天新招聘的学生不能在当天继续招聘其他人。 - 如果学生
$2i$不在工作且$2i \leq 10^{10^{100}}$,那么他开始工作。- 如果学生
$2i + 1$不在工作且$2i + 1 \leq 10^{10^{100}}$,那么他开始工作。
- 如果学生
- 解雇。 你可以选择任意一组正在工作的学生,并分别直接解雇他们。如果学生
$i$被直接解雇,那么他的所有下属也会被自动解雇。这类解雇称为间接解雇。学生$1$不能被解雇。
Additional restriction: Each student may be fired (directly or indirectly) at most once. If a previously fired student is hired again, it is forbidden to perform a firing that would cause this student to be fired again.
附加限制: 每名学生最多只能被解雇一次(直接或间接)。如果一名此前被解雇的学生再次被招聘,则禁止进行任何会再次导致该学生被解雇的解雇操作。AI (CI翻译)
Below (showing only the first $15$ students) are examples of how to choose students for direct firing on each day so that after $2$ days exactly $5$ students remain. The number at the top corresponds to the student number, edges show subordination.
下面展示了(仅显示前 $15$ 名学生)如何选择每天直接解雇的学生,使得 $2$ 天后恰好剩下 $5$ 名学生。顶部的数字对应学生编号,边表示下属关系。AI (CI翻译)
Students who are working and have not been fired are marked green, students who have been fired are marked white, and students who were previously fired but have been rehired are marked red.
正在工作的且从未被解雇的学生标为绿色,已经被解雇的学生标为白色,之前被解雇但又被重新招聘的学生标为红色。AI (CI翻译)
Day $1$, before firing. All students are hired.
Day $1$, after firing. Students $2$, $6$, $7$ are fired.
Day $2$, before firing. Students $2$, $6$, $7$ are hired. Note that during the firing stage, student $3$ cannot be directly fired, as this would lead to firing students $6$ and $7$, who have already been fired before this moment.
第 $1$ 天,解雇前。所有学生都已被招聘。
第 $1$ 天,解雇后。学生 $2$、$6$、$7$ 被解雇。
第 $2$ 天,解雇前。学生 $2$、$6$、$7$ 被招聘。注意,在解雇阶段不能直接解雇学生 $3$,因为这会导致此前已经被解雇过的学生 $6$ 和 $7$ 再次被解雇。AI (CI翻译)
Your goal is to make it so that exactly $n$ days later there are exactly $k$ working students left in the project. At the same time, you need to minimize the total number of direct firings over the whole period.
你的目标是使得恰好经过 $n$ 天后,项目中恰好剩下 $k$ 名正在工作的学生。同时,你需要最小化整个期间直接解雇的总次数。AI (CI翻译)
Find the number of ways to choose the students for direct firing on each day so that the final number of working students is $k$, and the total number of direct firings is minimal possible. Output the answer modulo $10^9 + 7$.
请计算满足最终剩余正在工作的学生数为 $k$,且直接解雇总次数达到最小值时,每天选择直接解雇学生的方案数。答案对 $10^9 + 7$ 取模。AI (CI翻译)
Input
输入格式
AI (CI翻译)Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^5$). The description of the test cases follows.
每个测试包含多个测试用例。第一行包含测试用例数量 $t$($1 \le t \le 10^5$)。接下来描述各个测试用例。AI (CI翻译)
The first line of each test case contains two integers $n$ and $k$ ($1 \le n \le 10^9$, $1 \le k \le 2 \cdot 10^5$) — the number of days and the required final number of active students.
每个测试用例的第一行包含两个整数 $n$ 和 $k$($1 \le n \le 10^9$,$1 \le k \le 2 \cdot 10^5$),分别表示天数和要求最终剩余的正在工作的学生数。AI (CI翻译)
Output
输出格式
AI (CI翻译)For each test case, output one integer — the number of possible ways to choose firings on each day so that after $n$ days exactly $k$ students remain, under the condition that the total number of firings is minimal possible.
对于每个测试用例,输出一个整数——经过 $n$ 天后恰好剩下 $k$ 名学生时,选择每天进行解雇的方案数,其中直接解雇的总次数必须达到最小值。AI (CI翻译)
Note
说明
AI (CI翻译)In the first test case, there is $1$ way: on the first day, directly fire students numbered $2$ and $3$. Exactly one student, number $1$, remains.
在第一个测试用例中,方案数为 $1$:第一天直接解雇编号为 $2$ 和 $3$ 的学生。最终只剩下编号为 $1$ 的学生。AI (CI翻译)
In the second test case, there are $2$ possible ways:
在第二个测试用例中,有 $2$ 种可能的方案:AI (CI翻译)
- On the first day, directly fire students numbered
$2$,$6$, and$7$. Students$1$and$3$remain. At the beginning of the second day, they hire students numbered$2$,$6$, and$7$. - On the first day, directly fire students numbered
$3$,$4$, and$5$. Students$1$and$2$remain. At the beginning of the second day, they hire students numbered$3$,$4$, and$5$.
- 第一天直接解雇学生
$2$、$6$和$7$。学生$1$和$3$留下。在第二天开始时,他们招聘学生$2$、$6$和$7$。 - 第一天直接解雇学生
$3$、$4$和$5$。学生$1$和$2$留下。在第二天开始时,他们招聘学生$3$、$4$和$5$。
It can be shown that it is impossible to end with $5$ students by firing fewer than three students.
可以证明,直接解雇少于三名学生时,不可能最终剩下 $5$ 名学生。AI (CI翻译)
In the third test case, there are $2$ possible ways:
在第三个测试用例中,有 $2$ 种可能的方案:AI (CI翻译)
- On the first day, directly fire student
$3$. On the second day, student$1$hires student$3$. We fire nobody. On the third day, student$3$hires students$6$and$7$. After that, directly fire student$2$. Thus,$4$students remain:$1$,$3$,$6$, and$7$. - On the first day, directly fire student
$2$. On the second day, student$1$hires student$2$. We fire nobody. On the third day, student$2$hires students$4$and$5$. After that, directly fire student$3$. Thus,$4$students remain:$1$,$2$,$4$, and$5$.
- 第一天直接解雇学生
$3$。第二天,学生$1$招聘学生$3$。当天不进行解雇。第三天,学生$3$招聘学生$6$和$7$。之后直接解雇学生$2$。最终剩下学生$1$、$3$、$6$和$7$,共$4$名。 - 第一天直接解雇学生
$2$。第二天,学生$1$招聘学生$2$。当天不进行解雇。第三天,学生$2$招聘学生$4$和$5$。之后直接解雇学生$3$。最终剩下学生$1$、$2$、$4$和$5$,共$4$名。
It can be shown that it is impossible to end with $4$ students by directly firing fewer than two students.
可以证明,直接解雇少于两名学生时,不可能最终剩下 $4$ 名学生。
AI (CI翻译)
样例
6
1 1
2 5
3 4
1 5
20 14
1000000000 20
1
2
2
42
120
12
题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。