#P4257. 可爱の#10数字划分

    ID: 3184 远端评测题 1000~10000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>O2优化排序素数判断,质数,筛法概率论,统计

可爱の#10数字划分

Description

We stipulate:

  1. A prime number can only be placed in the same set with prime numbers.
  2. A composite number can only be placed in the same set with composite numbers (11 is considered composite).
  3. Let the union of all prime-number sets be UU (i.e., the union of all prime-number sets including SS). For each prime-number set SS, define its value as:
$$V_S=\frac {(\sum_{i\in S}V_i)^p} {\prod_{i\in U}V_i}.$$
  1. For each composite-number set SS, define its value as follows:

Let k=Sk=|S|. Use these kk numbers as the weights of kk edges to connect k+1k+1 vertices, forming a tree. For a permutation P(1k+1)P(1 \sim k+1), the value is:

VP=i=1kf(Pi,Pi+1),V_P=\sum_{i=1}^{k} f(P_i,P_{i+1}),

where f(u,v)f(u,v) is the maximum edge weight on the path (u,v)(u,v).

The value of the set SS is:

VS=E(min{VP})×S,V_S=E(\min\{V_P\})\times|S|,

where E(X)E(X) denotes the mathematical expectation of XX over all possible labeled unrooted trees, and the min\min is taken over all possible PP. Here, all elements in the set are distinct, i.e., all edges are distinct.

  1. The value of a partition scheme is defined as the product of the values of all sets.
  2. 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 n,pn, p and ViV_i, please compute the sum of values over all valid and distinct partition schemes.

Take the result modulo 109+710^9+7. For division, please use multiplicative inverses.

Input Format

The first line contains two positive integers n,pn, p.

The second line contains nn positive integers ViV_i.

Output Format

Output a single non-negative integer: the answer modulo 109+710^9+7.

4 1
1 2 3 4

333333359

Hint

Sample Explanation

There are the following 66 partition schemes:

  1. (2,3)(2,3) and (1,4)(1,4). The value of (2,3)(2,3) is 56{\dfrac 5 6}, the value of (1,4)(1,4) is 1010, and the total value is 253{\dfrac {25} 3}.
  2. (2),(3)(2),(3) and (1,4)(1,4). The value of (2)(2) is 11, the value of (3)(3) is 12{\dfrac 1 2}, the value of (1,4)(1,4) is 1010, and the total value is 55.
  3. (3),(2)(3),(2) and (1,4)(1,4). The value of (3)(3) is 11, the value of (2)(2) is 13{\dfrac 1 3}, the value of (1,4)(1,4) is 1010, and the total value is 103{\dfrac {10} 3}.
  4. (2,3)(2,3) and (1),(4)(1),(4). The value of (2,3)(2,3) is 56{\dfrac 5 6}, the value of (1)(1) is 11, the value of (4)(4) is 44, and the total value is 103{\dfrac {10} 3}.
  5. (2),(3)(2),(3) and (1),(4)(1),(4). The value of (2)(2) is 11, the value of (3)(3) is 12{\dfrac 1 2}, the value of (1)(1) is 11, the value of (4)(4) is 44, and the total value is 22.
  6. (3),(2)(3),(2) and (1),(4)(1),(4). The value of (3)(3) is 11, the value of (2)(2) is 13{\dfrac 1 3}, the value of (1)(1) is 11, the value of (4)(4) is 44, and the total value is 43{\dfrac 4 3}.

Therefore, the sum of values over all partition schemes is 703{\dfrac {70} 3}. After taking modulo 109+710^9+7, the result is 333333359333333359.

Constraints

For 100%100\% of the testdata, 1n701 \le n \le 70, 1Vi10121 \le V_i \le 10^{12}.

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