CF2238F.Infinite Work

省选/NOI-

通过率:0%

时间限制:2.50s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

More monkeys!

— Exponential Idle

You are in charge of a large scientific project studying an unusual function. To carry it out, you hired 101010010^{10^{100}} students and numbered them with natural numbers from 11 to 101010010^{10^{100}}. The students form a hierarchy:

  • Student 11 is the main one.
  • For any i≥2i \geq 2, the direct supervisor of student ii is student ⌊i2⌋\left\lfloor \frac{i}{2} \right\rfloor.
  • The direct subordinates of student ii are students 2i2i and 2i+12i+1 (if these numbers do not exceed 101010010^{10^{100}}).
  • Subordination is transitive: if aa is subordinate to bb, and bb is subordinate to cc, then aa is subordinate to cc.

Initially, all students are working.

There are nn days left until the project is completed. Each day consists of two stages:

  • Hiring. Each working student ii hires all the non-working students who are directly subordinate to him:
    • If student 2i2i is not working and 2i≤10101002i \leq 10^{10^{100}}, he starts working.
    • If student 2i+12i + 1 is not working and 2i+1≤10101002i + 1 \leq 10^{10^{100}}, he starts working.Newly hired students cannot hire anyone on the same day.
  • Firing. You may choose any set of working students and directly fire each of them. If student ii is directly fired, then all of his subordinates are automatically fired as well. Such firings are called indirect. Student 11 cannot be fired.

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.

Below (showing only the first 1515 students) are examples of how to choose students for direct firing on each day so that after 22 days exactly 55 students remain. The number at the top corresponds to the student number, edges show subordination.

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.

Day 11, before firing. All students are hired. Day 11, after firing. Students 22, 66, 77 are fired. Day 22, before firing. Students 22, 66, 77 are hired. Note that during the firing stage, student 33 cannot be directly fired, as this would lead to firing students 66 and 77, who have already been fired before this moment.

Your goal is to make it so that exactly nn days later there are exactly kk working students left in the project. At the same time, you need to minimize the total number of direct firings over the whole period.

Find the number of ways to choose the students for direct firing on each day so that the final number of working students is kk, and the total number of direct firings is minimal possible. Output the answer modulo 109+710^9 + 7.

更多猴子!

——《指数空闲》

你负责一个大型科学研究项目,研究一种特殊的函数。为开展该项目,你雇佣了 101010010^{10^{100}} 名学生,并用从 11 到 101010010^{10^{100}} 的自然数对他们进行编号。这些学生构成一个层级结构:

  • 学生 11 是总负责人;
  • 对任意 i≥2i \geq 2,学生 ii 的直属上级是学生 ⌊i2⌋\left\lfloor \frac{i}{2} \right\rfloor;
  • 学生 ii 的直属下属是学生 2i2i 和 2i+12i+1(前提是这两个编号不超过 101010010^{10^{100}});
  • 隶属关系具有传递性:若 aa 隶属于 bb,且 bb 隶属于 cc,则 aa 隶属于 cc。

初始时,所有学生均处于工作状态。

距离项目完成还剩 nn 天。每一天包含两个阶段:

  • 招聘阶段:每个正在工作的学生 ii 将招聘其所有尚未工作的直属下属:
    • 若学生 2i2i 尚未工作,且 2i≤10101002i \leq 10^{10^{100}},则他开始工作;
    • 若学生 2i+12i + 1 尚未工作,且 2i+1≤10101002i + 1 \leq 10^{10^{100}},则他开始工作。
      当日新招聘的学生不能在同一天内再招聘他人。
  • 解雇阶段:你可以任选一组正在工作的学生,直接解雇其中每一位。若学生 ii 被直接解雇,则其所有下属也将被自动解雇(此类解雇称为间接解雇)。学生 11 不可被解雇。

附加限制:每位学生至多被解雇(直接或间接)一次。若某位先前已被解雇的学生被重新招聘,则禁止执行会导致该学生再次被解雇的任何解雇操作。

下图(仅展示前 1515 名学生)给出了一个示例:通过在每天选择适当的人员进行直接解雇,使得经过 22 天后恰好剩余 55 名学生。顶部数字表示学生编号,连线表示隶属关系。

正在工作且未被解雇的学生以绿色标记;已被解雇的学生以白色标记;此前曾被解雇但已被重新招聘的学生以红色标记。

第 11 天,解雇前。所有学生均已招聘。
第 11 天,解雇后。学生 22、66、77 被解雇。
第 22 天,解雇前。学生 22、66、77 被重新招聘。注意:在解雇阶段,学生 33 不可被直接解雇,因为这将导致学生 66 和 77 被解雇,而他们在此刻之前已被解雇过。

你的目标是:恰好经过 nn 天后,项目内恰好剩下 kk 名正在工作的学生。同时,你需要使整个期间内直接解雇的总人数最小。

请计算满足以下条件的方案数:每天选择哪些学生进行直接解雇,使得最终剩余的工作学生数恰好为 kk,且直接解雇的总人数达到最小可能值。输出答案对 109+710^9 + 7 取模的结果。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1051 \le t \le 10^5). The description of the test cases follows.

The first line of each test case contains two integers nn and kk (1≤n≤1091 \le n \le 10^9, 1≤k≤2⋅1051 \le k \le 2 \cdot 10^5) — the number of days and the required final number of active students.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1051 \le t \le 10^5)。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 kk(1≤n≤1091 \le n \le 10^9,1≤k≤2⋅1051 \le k \le 2 \cdot 10^5)——分别表示天数和所需的最终活跃学生人数。

输出格式

For each test case, output one integer — the number of possible ways to choose firings on each day so that after nn days exactly kk students remain, under the condition that the total number of firings is minimal possible.

对于每个测试用例,输出一个整数——在满足总解雇人数最少的前提下,选择每天解雇方案的方法数,使得经过 nn 天后恰好剩下 kk 名学生。

输入输出样例

  • 输入#1

    6
    1 1
    2 5
    3 4
    1 5
    20 14
    1000000000 20

    输出#1

    1
    2
    2
    42
    120
    12

说明/提示

In the first test case, there is 11 way: on the first day, directly fire students numbered 22 and 33. Exactly one student, number 11, remains.

In the second test case, there are 22 possible ways:

  • On the first day, directly fire students numbered 22, 66, and 77. Students 11 and 33 remain. At the beginning of the second day, they hire students numbered 22, 66, and 77.
  • On the first day, directly fire students numbered 33, 44, and 55. Students 11 and 22 remain. At the beginning of the second day, they hire students numbered 33, 44, and 55.

It can be shown that it is impossible to end with 55 students by firing fewer than three students.

In the third test case, there are 22 possible ways:

  • On the first day, directly fire student 33. On the second day, student 11 hires student 33. We fire nobody. On the third day, student 33 hires students 66 and 77. After that, directly fire student 22. Thus, 44 students remain: 11, 33, 66, and 77.
  • On the first day, directly fire student 22. On the second day, student 11 hires student 22. We fire nobody. On the third day, student 22 hires students 44 and 55. After that, directly fire student 33. Thus, 44 students remain: 11, 22, 44, and 55.

It can be shown that it is impossible to end with 44 students by directly firing fewer than two students.

在第一个测试用例中,有 11 种方式:第一天直接解雇编号为 22 和 33 的学生。恰好剩下一学生,即编号为 11 的学生。

在第二个测试用例中,有 22 种可能的方式:

  • 第一天直接解雇编号为 22、66 和 77 的学生。学生 11 和 33 剩余。第二天开始时,他们重新雇佣编号为 22、66 和 77 的学生。
  • 第一天直接解雇编号为 33、44 和 55 的学生。学生 11 和 22 剩余。第二天开始时,他们重新雇佣编号为 33、44 和 55 的学生。

可以证明:若想最终剩下 55 名学生,则直接解雇的学生人数不可能少于三人。

在第三个测试用例中,有 22 种可能的方式:

  • 第一天直接解雇学生 33;第二天,学生 11 雇佣学生 33,不进行任何解雇;第三天,学生 33 雇佣学生 66 和 77;随后直接解雇学生 22。最终剩余 44 名学生:11、33、66 和 77。
  • 第一天直接解雇学生 22;第二天,学生 11 雇佣学生 22,不进行任何解雇;第三天,学生 22 雇佣学生 44 和 55;随后直接解雇学生 33。最终剩余 44 名学生:11、22、44 和 55。

可以证明:若想最终剩下 44 名学生,则直接解雇的学生人数不可能少于两人。

输入解题思路,AI测评打分。不知道怎么写?

首页