#P4257. 可爱の#10数字划分
可爱の#10数字划分
Description
We stipulate:
- A prime number can only be placed in the same set with prime numbers.
- A composite number can only be placed in the same set with composite numbers ( is considered composite).
- Let the union of all prime-number sets be (i.e., the union of all prime-number sets including ). For each prime-number set , define its value as:
- For each composite-number set , define its value as follows:
Let . Use these numbers as the weights of edges to connect vertices, forming a tree. For a permutation , the value is:
where is the maximum edge weight on the path .
The value of the set is:
where denotes the mathematical expectation of over all possible labeled unrooted trees, and the is taken over all possible . Here, all elements in the set are distinct, i.e., all edges are distinct.
- The value of a partition scheme is defined as the product of the values of all sets.
- Two partition schemes are the same if and only if their sets correspond exactly and the relative order of the prime-number sets is the same.
Now, given and , please compute the sum of values over all valid and distinct partition schemes.
Take the result modulo . For division, please use multiplicative inverses.
Input Format
The first line contains two positive integers .
The second line contains positive integers .
Output Format
Output a single non-negative integer: the answer modulo .
4 1
1 2 3 4
333333359
Hint
Sample Explanation
There are the following partition schemes:
- and . The value of is , the value of is , and the total value is .
- and . The value of is , the value of is , the value of is , and the total value is .
- and . The value of is , the value of is , the value of is , and the total value is .
- and . The value of is , the value of is , the value of is , and the total value is .
- and . The value of is , the value of is , the value of is , the value of is , and the total value is .
- and . The value of is , the value of is , the value of is , the value of is , and the total value is .
Therefore, the sum of values over all partition schemes is . After taking modulo , the result is .
Constraints
For of the testdata, , .
The table below gives the specific constraints for each test point (all are upper bounds). To prevent stressing the OJ, the testdata is compressed and the scores are adjusted; see the table for details.
| Data ID | n | p | V_i | Score per test point | Time limit |
|---|---|---|---|---|---|
| 1 | 10 | 1 | 100 | 10 | 1 s |
| 2 | 20 | 1000 | |||
| 3 | 30 | 10000 | |||
| 4 | 40 | 1e9 | 1e12 | ||
| 5 | 50 | 1 | 5 | ||
| 6 | 1e9 | ||||
| 7 | 60 | 1 | 2 s | ||
| 8 | 1e9 | ||||
| 9 | 70 | 20 | 10 s | ||
| 10 | 5 s |
Tip: Do not be overly optimistic about constant factors; try to optimize them.
Translated by ChatGPT 5
京公网安备 11011102002149号