#P4448. [AHOI2018初中组] 球球的排列
[AHOI2018初中组] 球球的排列
Description
Xiao Keke is a person with special hobbies. He especially likes collecting all kinds of balls, and has collected balls so far.
Xiao Keke also has special ideas. He numbers all his balls from 1 to , and arranges the balls into a brand-new permutation every day.
Xiao Keke also has special feelings. He represents the attribute of each ball by (note that can be the same for different balls).
Xiao Keke is a person of clear likes and dislikes. He hates perfect squares, so he stipulates: for a permutation , for all , is not a perfect square; only such a permutation is valid.
He keeps arranging a brand-new valid permutation every day. One day, on a whim, he wants to know the number of all valid permutations. Xiao Keke is very strong and certainly knows how to compute it. However, he wants to test you with this problem. This number can be very large, so you only need to tell him the number of valid permutations modulo .
Can you answer Xiao Keke’s question correctly? If you can, he might even give you a ball.
Input Format
The input has two lines:
- The first line contains a positive integer , the number of balls that Xiao Keke has.
- The second line contains integers; the -th integer denotes the attribute of the ball with index .
Output Format
Output one line containing a single positive integer, the number of valid permutations modulo (i.e., 1000000007).
4
2 2 3 4
12
9
2 4 8 9 12 4 3 6 11
99360
Hint
[Sample 1 Explanation]
There are 12 valid permutations:
1,3,2,4
2,3,1,4
3,1,4,2
3,2,4,1
1,3,4,2
2,3,4,1
1,4,2,3
2,4,1,3
4,1,3,2
4,2,3,1
1,4,3,2
2,4,3,1
Constraints
For 100% of the testdata: , .
This problem has 10 test points, numbered 1-10; each test point additionally guarantees the following:
| Test point id | Range of n | Range of |
|---|---|---|
| 1-2 | ||
| 3-5 | ||
| 6-8 | - | and all are primes |
| 9-10 |
Translated by ChatGPT 5
京公网安备 11011102002149号