CF1558B.Up the Strip

普及+/提高

通过率:0%

时间限制:6.00s

内存限制:128MB

AC君温馨提醒

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

题目描述

Note that the memory limit in this problem is lower than in others.

You have a vertical strip with nn cells, numbered consecutively from 11 to nn from top to bottom.

You also have a token that is initially placed in cell nn. You will move the token up until it arrives at cell 11.

Let the token be in cell x>1x \gt 1 at some moment. One shift of the token can have either of the following kinds:

  • Subtraction: you choose an integer yy between 11 and x−1x-1, inclusive, and move the token from cell xx to cell x−yx - y.
  • Floored division: you choose an integer zz between 22 and xx, inclusive, and move the token from cell xx to cell ⌊xz⌋\lfloor \frac{x}{z} \rfloor (xx divided by zz rounded down).

Find the number of ways to move the token from cell nn to cell 11 using one or more shifts, and print it modulo mm. Note that if there are several ways to move the token from one cell to another in one shift, all these ways are considered distinct (check example explanation for a better understanding).

注意:本题的内存限制比其他题目更低。

你有一条垂直的格子带,共 nn 个格子,从上到下依次编号为 11 到 nn。

你还拥有一个初始位于第 nn 个格子的标记(token)。你需要将该标记向上移动,直至到达第 11 个格子。

假设在某一时刻,标记位于第 xx 个格子,且 x>1x > 1。一次移动操作有以下两种类型之一:

  • 减法操作:你选择一个整数 yy,满足 1≤y≤x−11 \le y \le x-1,并将标记从第 xx 个格子移动到第 x−yx - y 个格子;
  • 向下取整除法操作:你选择一个整数 zz,满足 2≤z≤x2 \le z \le x,并将标记从第 xx 个格子移动到第 ⌊xz⌋\lfloor \frac{x}{z} \rfloor 个格子(即 xx 除以 zz 后向下取整)。

求出将标记从第 nn 个格子移动到第 11 个格子所需的一次或多次移动操作的方案总数,并将结果对 mm 取模后输出。注意:若存在多种方式通过一次移动操作将标记从某格子移动至另一格子,则这些方式均被视为互不相同的方案(参见样例解释以获得更清晰的理解)。

输入格式

The only line contains two integers nn and mm (2≤n≤4⋅1062 \le n \le 4 \cdot 10^6; 108<m<10910^8 \lt m \lt 10^9; mm is a prime number) — the length of the strip and the modulo.

唯一一行包含两个整数 nn 和 mm(2≤n≤4⋅1062 \le n \le 4 \cdot 10^6;108<m<10910^8 \lt m \lt 10^9;mm 是一个质数)—— 分别表示条带的长度和取模数。

输出格式

Print the number of ways to move the token from cell nn to cell 11, modulo mm.

输出将棋子从第 nn 个格子移动到第 11 个格子的方法数,对 mm 取模。

输入输出样例

  • 输入#1

    3 998244353

    输出#1

    5
  • 输入#2

    5 998244353

    输出#2

    25
  • 输入#3

    42 998244353

    输出#3

    793019428
  • 输入#4

    787788 100000007

    输出#4

    94810539

说明/提示

In the first test, there are three ways to move the token from cell 33 to cell 11 in one shift: using subtraction of y=2y = 2, or using division by z=2z = 2 or z=3z = 3.

There are also two ways to move the token from cell 33 to cell 11 via cell 22: first subtract y=1y = 1, and then either subtract y=1y = 1 again or divide by z=2z = 2.

Therefore, there are five ways in total.

在第一个测试中,有三种方式可以在一次移动中将棋子从第 33 个格子移动到第 11 个格子:使用减法(y=2y = 2),或使用除法(z=2z = 2 或 z=3z = 3)。

此外,还有两种方式可以通过第 22 个格子将棋子从第 33 个格子移动到第 11 个格子:先减去 y=1y = 1,然后再次减去 y=1y = 1,或除以 z=2z = 2。

因此,总共有五种方式。

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

首页