#P4935. 口袋里的纸飞机
口袋里的纸飞机
Description
Given a sequence of length , , where each number is in the range .
For each sequence, you can generate an grid, where the value in cell is .
For example, if the sequence is and , 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 , i.e. .
Now you need to compute the sum of the fafa values over all sequences, and take it modulo .
Input Format
The first line contains positive integers .
Output Format
Output the answer modulo .
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 is a prime number with .
Constraints
| Test Point | |||
|---|---|---|---|
| 1,2 | |||
| 3,4,5,6 | |||
| 7,8 | |||
| 9,10,11,12 | |||
| 13,14,15,16 | |||
| 17,18,19,20 |
For all data, .
Translated by ChatGPT 5
京公网安备 11011102002149号