Expected Number of Connected Components
Time limit5sMemory limit512 MB
For each node i with inclusion probability P_i, find the expected number of connected components of the subgraph where two selected nodes are adjacent when gcd > 1, then print E times 100^N mod 1e9+7.
- Level
Hard8 of 10
- Topics
- Probability, Math, Number theory, Union-find
- Solved
- No attempts yet
Problem
There are nodes, numbered with the distinct integers from 1 to . You pick a random subset of these nodes. Node enters the subset with probability , independently of every other node.
Two nodes in the subset are joined by an edge when the greatest common divisor of their numbers is larger than 1. Find the expected number of connected components of the resulting subgraph.
Input
The first line has the number of test cases ().
Each test case takes two lines. The first line has the number of nodes (). The second line has real numbers separated by spaces. The -th real number is the probability that node is in the subset (, ). Each real number is given with at most two digits after the decimal point.
Output
For each test case, let be the expected number of connected components. Print modulo on its own line. The value is always an integer.
Notes
The greatest common divisor of node 1 and any other node is 1, so node 1 always forms a component by itself when it is in the subset.
Take with all four probabilities equal to . Each of the 16 subsets appears with probability , and the component counts of those 16 subsets add up to 28. The expected value is , so the value to print is .