PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SRD0000128. Đi ngược trên dải ô (Up the Strip (Hard Version))

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đi ngược trên dải ô (Up the Strip (Hard Version))

Up the Strip (Hard Version)

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

There is a vertical strip of nn cells numbered 11 through nn from top to bottom. A token starts at cell nn and must reach cell 11.

At cell x>1x>1, choose exactly one operation:

  1. Subtraction: choose 1≤y≤x−11\le y\le x-1 and move to x−yx-y.
  2. Floored division: choose 2≤z≤x2\le z\le x and move to ⌊x/z⌋\lfloor x/z\rfloor.

Count all sequences of choices ending at cell 11, modulo mm. Different operation choices count as different ways even if they lead to the same destination.

Input

One line with two integers n,mn,m.

Output

Print the answer modulo mm.

Subtasks

In all subtasks, 108<m<10910^8<m<10^9 and mm is prime.

  • Subtask 1 (10 points): 2≤n≤1002\le n\le100.
  • Subtask 2 (20 points): 2≤n≤1042\le n\le10^4.
  • Subtask 3 (30 points): 2≤n≤4⋅1052\le n\le4\cdot10^5.
  • Subtask 4 (40 points): 2≤n≤4⋅1062\le n\le4\cdot10^6 (full original limits).

Examples

Example 1

Input

3 998244353

Output

5

Explanation: There are three direct choices from cell 33 to 11 (subtract 22, divide by 22 or 33), and two choices via cell 22.

Example 2

Input

5 998244353

Output

25

Explanation: If f(x)f(x) counts paths from xx to 11, then f(1)=1f(1)=1, f(2)=2f(2)=2, f(3)=5f(3)=5, f(4)=12f(4)=12 and f(5)=25f(5)=25.

Example 3

Input

42 998244353

Output

793019428

Explanation: Applying the same recurrence and reducing modulo 998244353998244353 yields 793019428793019428.

Example 4

Input

787788 100000007

Output

94810539

Explanation: The recurrence evaluated modulo 100000007100000007 yields 9481053994810539.