Expected Value of a Permutation
Time limit1sMemory limit512 MB
Find the expected total of sums of arrays that zero all indices divisible by each next permutation value, and output that expectation mod 1000000007.
- Level
Medium7 of 10
- Topics
- Math, Number theory, Prefix sum, Implementation
- Solved
- No attempts yet
Problem
You are given an array of integers . Summing every element of is boring, so you decided to take it to the next level. A permutation of to is generated at random. Each permutation of to has an equal probability of being chosen as .
You also define arrays and an integer as follows.
- For , is with every element whose index is a multiple of changed to .
- , where is the sum of every integer in .
For example, if and , then:
- because , so the 3rd element of becomes .
- because , so the 2nd and 4th elements of become .
- because , so the 4th element of becomes .
- because , so every element of becomes .
- because , so the 5th element of becomes .
Therefore in this case.
Since is generated at random, you wonder about the expected value of . Let be the expected value of , where and are relatively prime non-negative integers. Print the value of . In other words, print the unique integer () satisfying .
Input
The first line contains an integer (), the number of integers in . The second line contains integers (), which form the array .
Output
Print the expected value of on one line, in the format specified in the problem description.