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>();
        var mf=MinFactors(a.Max());
        for(var i=0;i<n;i++){
            var tmp=PrimeFactors(a[i],mf);
            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 ldn=(ulong)1;
        var mdn=(ulong)(Math.Pow(10,9)+7);
        foreach(var v in l) {
            for(var i=0;i<v.Value;i++){
                ldn=(ldn*(ulong)v.Key%mdn)%mdn;
            }
        }
        var ans=(ulong)0;
        for(var i=0;i<n;i++){
            ans=((ans%mdn)+ldn*modinv((ulong)a[i],mdn)%mdn)%mdn;
        }
        Console.WriteLine(ans);
    }

    static Dictionary<int,int> PrimeFactors(int n,Dictionary<int,int> mf)
    {
        var cnt=new Dictionary<int,int>();

        while (n > 1)
        {
            var prime=mf[n];
            var exp=0;
            while(mf[n]==prime){
                exp++;
                n /= prime;
            }
            cnt.Add(prime,exp);
        }
        return cnt;
    }
    
    static Dictionary<int,int> MinFactors(int n){
        var mf=new Dictionary<int,int>();
        
        for(var i=0;i<=n;i++){
            mf.Add(i,i);
        }
        
        for(var i=2;i*i<=n;i++){
            if(mf[i]==i){
                mf[i]=i;
                for(var j=i*i;j<=n;j+=i){
                    if(mf[j]==j) mf[j]=i;
                }
            }
        }
        
        return mf;
    }
    
    static ulong modinv(ulong a,ulong m){
        var b=m;
        var u=(ulong)1;
        var v=(ulong)0;
        while(b>0){
            ulong t=a/b;
            a-=t*b;Swap(ref a,ref b);
            u-=t*v;Swap(ref u,ref v);
        }
        u%=m;
        if(u<0) u+=m;
        return u;
    }
    
    static void Swap<T>(ref T lhs, ref T rhs)
    {
        T temp;
        temp = lhs;
        lhs = rhs;
        rhs = temp;
    }
}

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;
    }
}