Jack Needs Help

View as PDF

Submit solution

Points: 10 (partial)
Time limit: 1.0s
Java 2.0s
Python 2.0s
Memory limit: 256M

Author:
Problem type

Jack is planning something and needs your help. Jack needs your help to finish his math homework because he slept through class and has no idea what he is doing. He is given an array a which satisfies 1ai2×105 for all i (1in). A new array b is generated which satisfies 0bi<ai for all i (1in). For each bi, all integers in the range [0,ai) have an equal chance of being chosen.

Jack wants to know the probability that the array b is beautiful.

Array b is beautiful if there exists an integer x such that xbi(modai) for each i (1in). This probability can be represented as pq where p and q are relatively prime.

Since p and q might be really large, Jack would like to receive the answer as p+q, modulo 109+7.

Constraints

1N2×105
1ai2×105

Subtask 1 [15%]

ai is prime.

Subtask 2 [15%]

N=2

Subtask 3 [70%]

No additional constraints.

Input Specification

The first line contains N (1N2×105).
The next line contains N integers, the ith of which is ai.

Output Specification

Output p+q, modulo 109+7.

Sample Input 1

Copy
3
1 2 4

Sample Output 1

Copy
3

Explanation

There are 8 total possible arrays for b. Only 4 of those arrays are beautiful. They are {0,0,0}, {0,0,2}, {0,1,1} and {0,1,3}.
The probability can be expressed as 48 which simplifies to 12.
p+q=3 so the answer is 3.

Sample Input 2

Copy
4
83 838 8383 83838

Sample Output 2

Copy
167

Comments

There are no comments at the moment.