A14371 | Up the Strip
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Note that the memory limit in this problem is lower than in others.
You have a vertical strip with $n$ cells, numbered consecutively from $1$ to $n$ from top to bottom.
You also have a token that is initially placed in cell $n$ . You will move the token up until it arrives at cell $1$ .
Let the token be in cell $x > 1$ at some moment. One shift of the token can have either of the following kinds:
- Subtraction: you choose an integer $y$ between $1$ and $x-1$ , inclusive, and move the token from cell $x$ to cell $x - y$ .
- Floored division: you choose an integer $z$ between $2$ and $x$ , inclusive, and move the token from cell $x$ to cell $\lfloor \frac{x}{z} \rfloor$ ( $x$ divided by $z$ rounded down).
Find the number of ways to move the token from cell $n$ to cell $1$ using one or more shifts, and print it modulo $m$ . 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).
You have a vertical strip with $n$ cells, numbered consecutively from $1$ to $n$ from top to bottom.
You also have a token that is initially placed in cell $n$ . You will move the token up until it arrives at cell $1$ .
Let the token be in cell $x > 1$ at some moment. One shift of the token can have either of the following kinds:
- Subtraction: you choose an integer $y$ between $1$ and $x-1$ , inclusive, and move the token from cell $x$ to cell $x - y$ .
- Floored division: you choose an integer $z$ between $2$ and $x$ , inclusive, and move the token from cell $x$ to cell $\lfloor \frac{x}{z} \rfloor$ ( $x$ divided by $z$ rounded down).
Find the number of ways to move the token from cell $n$ to cell $1$ using one or more shifts, and print it modulo $m$ . 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).
输入格式
The only line contains two integers $n$ and $m$ ( $2 \le n \le 4 \cdot 10^6$ ; $10^8 < m < 10^9$ ; $m$ is a prime number) — the length of the strip and the modulo.
输出格式
Print the number of ways to move the token from cell $n$ to cell $1$ , modulo $m$ .
输入输出样例
输入 #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 $3$ to cell $1$ in one shift: using subtraction of $y = 2$ , or using division by $z = 2$ or $z = 3$ .
There are also two ways to move the token from cell $3$ to cell $1$ via cell $2$ : first subtract $y = 1$ , and then either subtract $y = 1$ again or divide by $z = 2$ .
Therefore, there are five ways in total.
There are also two ways to move the token from cell $3$ to cell $1$ via cell $2$ : first subtract $y = 1$ , and then either subtract $y = 1$ again or divide by $z = 2$ .
Therefore, there are five ways in total.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted