Codeforces Round 740 (Div. 2, based on VK Cup 2021 - Final (Engine))
D2
Up the Strip
Codeforces
未评级
原题
← D1E →
翻译中…

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 \gt 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).

翻译中…

Input

翻译中…

The only line contains two integers $n$ and $m$ ($2 \le n \le 4 \cdot 10^6$; $10^8 \lt m \lt 10^9$; $m$ is a prime number) — the length of the strip and the modulo.

翻译中…

Output

翻译中…

Print the number of ways to move the token from cell $n$ to cell $1$, modulo $m$.

翻译中…

Note

翻译中…

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.

翻译中…

样例

Input #1
3 998244353
Output #1
5
InputCopy OutputCopy
Input #2
5 998244353
Output #2
25
InputCopy OutputCopy
Input #3
42 998244353
Output #3
793019428
InputCopy OutputCopy
Input #4
787788 100000007
Output #4
94810539
InputCopy OutputCopy
题目信息
题号
1561D2
时间限制
6 s
内存限制
128 MB

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。