This page is still under construction.

Parts of this page are still being built. What you see may change.

Expected Value of a Permutation

Time limit1sMemory limit512 MB

Summary
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 NN integers A=[A1,A2,⋯ ,AN]A = [A_1, A_2, \cdots, A_N]. Summing every element of AA is boring, so you decided to take it to the next level. A permutation PP of 11 to NN is generated at random. Each permutation of 11 to NN has an equal probability of being chosen as PP.

You also define arrays X0,X1,X2,…,XNX_0, X_1, X_2, \ldots, X_N and an integer YY as follows.

  • X0=AX_0 = A
  • For 1≤i≤N1 \le i \le N, XiX_i is Xi−1X_{i-1} with every element whose index is a multiple of ii changed to 00.
  • Y=sum(X1)+sum(X2)+⋯+sum(XN)Y = \text{sum}(X_1) + \text{sum}(X_2) + \cdots + \text{sum}(X_N), where sum(Xi)\text{sum}(X_i) is the sum of every integer in XiX_i.

For example, if A=[4,1,2,3,4]A = [4, 1, 2, 3, 4] and P=[3,2,4,1,5]P = [3, 2, 4, 1, 5], then:

  • X0=[4,1,2,3,4]X_0 = [4, 1, 2, 3, 4]
  • X1=[4,1,0,3,4]X_1 = [4, 1, 0, 3, 4] because P1=3P_1 = 3, so the 3rd element of X1X_1 becomes 00.
  • X2=[4,0,0,0,4]X_2 = [4, 0, 0, 0, 4] because P2=2P_2 = 2, so the 2nd and 4th elements of X2X_2 become 00.
  • X3=[4,0,0,0,4]X_3 = [4, 0, 0, 0, 4] because P3=4P_3 = 4, so the 4th element of X3X_3 becomes 00.
  • X4=[0,0,0,0,0]X_4 = [0, 0, 0, 0, 0] because P4=1P_4 = 1, so every element of X4X_4 becomes 00.
  • X5=[0,0,0,0,0]X_5 = [0, 0, 0, 0, 0] because P5=5P_5 = 5, so the 5th element of X5X_5 becomes 00.

Therefore Y=12+8+8+0+0=28Y = 12 + 8 + 8 + 0 + 0 = 28 in this case.

Since PP is generated at random, you wonder about the expected value of YY. Let C/DC/D be the expected value of YY, where CC and DD are relatively prime non-negative integers. Print the value of (C×D−1) mod 1000000007(C \times D^{-1}) \bmod 1000000007. In other words, print the unique integer KK (0≤K<10000000070 \le K < 1000000007) satisfying C≡DK(mod1000000007)C \equiv DK \pmod{1000000007}.

Input

The first line contains an integer NN (1≤N≤1000001 \le N \le 100000), the number of integers in AA. The second line contains NN integers AiA_i (0≤Ai≤1090 \le A_i \le 10^9), which form the array AA.

Output

Print the expected value of YY on one line, in the format specified in the problem description.

Examples1

  1. Example 1

    Input
    5
    4 1 2 3 4
    
    Expected output
    500000020