#P10812. 【MX-S2-T3】 跳

    ID: 12271 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划 DPO2优化前缀和梦熊比赛

【MX-S2-T3】 跳

Background

Original problem link: https://oier.team/problems/S2C


Jump Jump is world No. 1.

No coaching, no apprentices. Find the gap by yourself.

Problem Description

Given a number line with positions from 11 to nn. From each position ii, you can jump to i+1i+1 (if i+1ni+1\le n), or to i1i-1 (if i11i-1\ge 1), or to one of its divisors. Each position can be visited at most once. Ask how many different ways there are to go from position nn to position 11. Output the answer modulo pp

Two ways are different if and only if there exists a jump after which the landing position is different, or there exists a jump whose type is different.

Input Format

One line with two integers n,pn,p

Output Format

One line with one integer, the answer modulo pp

3 1000000007
3
4 1000
7
100 511609
272799

Hint

[Sample Explanation #1]

Let \rightarrow denote jumping up or down by 11, and \Rightarrow denote jumping to a divisor. There are 33 ways in total, as follows.

  • 313\Rightarrow1
  • 3213\rightarrow2\rightarrow1
  • 3213\rightarrow2\Rightarrow1

[Sample Explanation #2]

Let \rightarrow denote jumping up or down by 11, and \Rightarrow denote jumping to a divisor. There are 77 ways in total, as follows.

  • 4314\rightarrow3\Rightarrow1
  • 43214\rightarrow3\rightarrow2\rightarrow1
  • 43214\rightarrow3\rightarrow2\Rightarrow1
  • 42314\Rightarrow2\rightarrow3\Rightarrow1
  • 4214\Rightarrow2\rightarrow1
  • 4214\Rightarrow2\Rightarrow1
  • 414\Rightarrow1

[Constraints]

This problem uses bundled testdata.

  • Subtask 0 (8 pts): n20n\le20
  • Subtask 1 (11 pts): n150n\le150
  • Subtask 2 (23 pts): n300n\le300
  • Subtask 3 (26 pts): n1000n\le1000
  • Subtask 4 (32 pts): no special constraints。

For all testdata, 1n5×1031\le n\le5\times10^3, 2p109+72\le p\le 10^9+7

Input Format

One line with two integers n,pn,p

Output Format

One line with one integer, the answer modulo pp

Translated by ChatGPT 5