#P2150. [NOI2015] 寿司晚宴

    ID: 1128 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划,dp数学2015NOI 系列状态压缩,状压素数判断,质数,筛法

[NOI2015] 寿司晚宴

Description

To celebrate the successful opening of NOI, the organizers prepared a sushi dinner. Xiao G and Xiao W, as NOI contestants, were invited to attend.

At the dinner, the organizers provided n1n - 1 different types of sushi, numbered 1,2,3,,n11, 2, 3, \ldots, n - 1, where the tastiness of the ii-th type is i+1i + 1 (that is, tastiness values range from 22 to nn).

Now Xiao G and Xiao W each want to choose some types of sushi to taste. A tasting plan is called discordant if and only if: there exists a sushi with tastiness xx chosen by Xiao G and a sushi with tastiness yy chosen by Xiao W such that xx and yy are not coprime.

They want to count how many harmonious tasting plans there are (i.e., plans that are not discordant), modulo a given positive integer pp. Note that a person may choose no sushi.

Input Format

The first line contains two positive integers n,pn, p separated by a single space. There are n1n - 1 types of sushi in total, with tastiness values from 22 to nn, and the final answer should be taken modulo pp.

Output Format

Output a single integer, which is the number of harmonious plans modulo pp.

3 10000
9
4 10000
21
100 100000000
3107203

Hint

[Constraints]

Test point ID Range of nn Convention
1 2n302 \le n \le 30 0<p1,000,000,0000 < p \le 1{,}000{,}000{,}000
2 Same as above. Same as above.
3
4 2n1002 \le n \le 100
5 Same as above.
6 2n2002 \le n \le 200
7 Same as above.
8 2n5002 \le n \le 500
9 Same as above.
10

Translated by ChatGPT 5