Problem:
Score : 500 points

Problem Statement

Given are N positive integers A_1,...,A_N.

Consider positive integers B_1, ..., B_N that satisfy the following condition.

Condition: For any i, j such that 1 \leq i < j \leq N, A_i B_i = A_j B_j holds.

Find the minimum possible value of B_1 + ... + B_N for such B_1,...,B_N.

Since the answer can be enormous, print the sum modulo (10^9 +7).

Constraints

1 \leq N \leq 10^4

1 \leq A_i \leq 10^6

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 ... A_N

Output

Print the minimum possible value of B_1 + ... + B_N for B_1,...,B_N that satisfy the condition, modulo (10^9 +7).

Sample Input 1

3
2 3 4

Sample Output 1

13

Let B_1=6, B_2=4, and B_3=3, and the condition will be satisfied.

Sample Input 2

5
12 12 12 12 12

Sample Output 2

5

We can let all B_i be 1.

Sample Input 3

3
1000000 999999 999998

Sample Output 3

996989508

Print the sum modulo (10^9+7).

Solution in C# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Collections.Generic;
using System.Linq;

public class Prime{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var a=Console.ReadLine().Trim().Split().Select(int.Parse).ToArray();
        var ap=new primenum[n];
        var l=new Dictionary<int,int>();
        for(var i=0;i<n;i++){
            var tmp=PrimeFactors(a[i]);
            ap[i]=new primenum(i,tmp);
            foreach(var v in tmp) {
                if(l.ContainsKey(v.Key)){
                    if(l[v.Key]<v.Value){
                        l[v.Key]=v.Value;
                    }
                }else{
                    l.Add(v.Key, v.Value);
                }
            }
        }
        var ans=(long)0;
        var mdn=(long)(Math.Pow(10,9)+7);
        for(var i=0;i<n;i++){
            var lasum=(long)1;
            foreach(var v in l) {
                var la=v.Value;
                if(ap[i].prime.ContainsKey(v.Key)){
                    la-=ap[i].prime[v.Key];
                }
                lasum*=(uint)Math.Pow(v.Key,la);
            }
            if(lasum>mdn) ans=ans%mdn+lasum%mdn;
            else          ans+=lasum;
            if(ans>mdn) ans %= mdn;
        }
        Console.WriteLine(ans);
    }

    public static Dictionary<int,int> PrimeFactors(int n)
    {
        var i = 2;
        var tmp = n;
        var cnt=new Dictionary<int,int>();

        while (i * i <= n)
        {
            if(tmp % i == 0){
                tmp /= i;
                if(cnt.ContainsKey(i)){
                    cnt[i]++;
                }else{
                    cnt.Add(i,1);
                }
            }else{
                i++;
            }
        }
        if(tmp != 1){
            cnt.Add(tmp,1);
        } 
        return cnt;
    }
}

public class primenum{
    public int num;
    public Dictionary<int,int> prime;
    public primenum(int n,Dictionary<int,int> p){
        this.num=n;
        this.prime=p;
}
    
}