#P4935. 口袋里的纸飞机

    ID: 3921 远端评测题 3000ms 500MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>数学素数判断,质数,筛法生成函数洛谷月赛

口袋里的纸飞机

Description

Given a sequence of length nn, {ai}\{a_i\}, where each number is in the range [1,R][1,R].

For each sequence, you can generate an n×nn\times n grid, where the value in cell (i,j)(i,j) is ai×ajmodPa_i\times a_j \bmod P.

For example, if the sequence is {1,2,3}\{1,2,3\} and P=5P=5, then the generated grid is

1 2 3
2 4 1
3 1 4(因为2*3%5=1,3*3%5=4)

For a grid, define its “fafa value” as the number of distinct values appearing in it. For the grid above, it is 44, i.e. {1,2,3,4}\{1,2,3,4\}.

Now you need to compute the sum of the fafa values over all sequences, and take it modulo 109+710^9+7.

Input Format

The first line contains positive integers n,P,Rn,P,R.

Output Format

Output the answer modulo 109+710^9+7.

2 3 3
15
4 7 5
2845
70 43 22
992103136
500 2011 999980895
767094932

Hint

Explanation for Sample 1:

{ai}={1,1}:
1 1
1 1
(ans=1)
{ai}={1,2}:
1 2
2 1
(ans=2)
{ai}={1,3}:
1 0
0 0
(ans=2)
{ai}={2,1}:
1 2
2 1
(ans=2)
{ai}={2,2}:
1 1
1 1
(ans=1)
{ai}={2,3}:
1 0
0 0
(ans=2)
{ai}={3,1}:
0 0
0 1
(ans=2)
{ai}={3,2}:
0 0
0 1
(ans=2)
{ai}={3,3}:
0 0
0 0
(ans=1)
Total is 15.

It is guaranteed that PP is a prime number with P3P\geq 3.

Constraints

Test Point NN RR PP
1,2 N5N\leq 5 R5R\leq 5 R×R<P20R\times R<P\leq 20
3,4,5,6 N15N\leq 15 R10R\leq 10 R×R<P200R\times R<P\leq 200
7,8 N30N\leq 30 R×R<P500R\times R<P\leq 500
9,10,11,12 N100N\leq 100
13,14,15,16 N300N\leq 300 R109R\leq 10^9 P1000P\leq 1000
17,18,19,20 N500N\leq 500 P5000P\leq 5000

For all data, n500,P5000,R109n\leq 500,P\leq 5000,R\leq 10^9.

Translated by ChatGPT 5