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: Time Limit Exceeded)

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Numerics;
using System.Text;

public class Test_152_e
{
  
        /// <summary>
        /// テスト環境の動作確認用
        /// </summary>
        public static void Main()
        {

            var N = Int32.Parse(Console.ReadLine());
            int[] a = new int[N];
            string[] ss = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < N; i++)
            {
                a[i] = int.Parse(ss[i]);
            }

            Console.WriteLine(Solve(a).ToString());
        }
  
        
        public static long Solve(int[] a)
        {
            var N = a.Length;

            int maxNum = a.Max();

            var prime = GeneratePrimesNaive(1000000);
            PrimeDigit.SetPrimes(prime);

            PrimeDigit d = new PrimeDigit(1);
            PrimeDigit[] rr = new PrimeDigit[N];
            for (int i = 0; i < N; i++)
            {
                PrimeDigit r = new PrimeDigit(a[i]);
                rr[i] = r;
                d = d.Gcd(r);
            }

            // 最小公倍数が求められた
            ModInt ans = ModInt.Zero;
            for (int i = 0; i < N; i++)
            {
                PrimeDigit t = d / rr[i];
                ans += t.ToModInt();
            }

            return ans.Val;
        }

        /// <summary>
        /// 数字を素数であらわす
        /// </summary>
        public class PrimeDigit
        {
            static List<int> primes = new List<int>();

            public static void SetPrimes(List<int> prime)
            {
                primes = prime;
            }

            public static PrimeDigit operator /(PrimeDigit a, PrimeDigit b)
            {
                int[] data = new int[primes.Count];
                for (int i = 0; i < primes.Count; i++)
                {
                    data[i] = a.data[i] - b.data[i];
                }
                return new PrimeDigit(data);
            }

            public PrimeDigit Gcd(PrimeDigit b)
            {
                int[] data = new int[primes.Count];
                // 最小公倍数 を求める
                for (int i = 0; i < primes.Count; i++)
                {
                    data[i] = Math.Max(this.data[i], b.data[i]);
                }

                return new PrimeDigit(data);
            }

            /// <summary>
            /// 数字を素因数分解して格納する領域
            /// </summary>
            public int[] data = new int[primes.Count];

            public PrimeDigit(int num)
            {
                int x = num;
                // 素数に分解
                for(int i=0;i<primes.Count;i++)
                {
                    int n = primes[i];
                    int m = 0;
                    while (x % n == 0)
                    {
                        m++;
                        x /= n;
                    }
                    if (m > 0)
                    {
                        data[i] = m;
                    }
                }
            }

            public PrimeDigit(int[] map)
            {
                for(int i=0;i < Math.Min(map.Length, data.Length); i++)
                {
                    data[i] = map[i];
                }
            }

            public BigInteger ToBigInteger()
            {
                BigInteger sum = BigInteger.One;
                for(int i=0;i< data.Length;i++)
                {
                    sum *= BigInteger.Pow(primes[i], data[i]);
                }
                
                return sum;
            }

            public override string ToString()
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("{" + this.ToBigInteger().ToString() + ":");
                for(int i=0;i<data.Length;i++) 
                {
                    if (data[i] > 0)
                    {
                        sb.Append("<" + primes[i] + "^" + data[i] + ">");
                    }
                }
                sb.Append("}");

                return sb.ToString();
            }

            internal ModInt ToModInt()
            {
                ModInt sum = ModInt.One;
                for (int i = 0; i < data.Length; i++)
                {
                    if (data[i] > 0)
                    {
                        sum *= ModInt.Pow(primes[i], data[i]);
                    }
                }
                return sum;
            }
        }

        /// <summary>
        /// 指定の数以下の 素数を一覧で表示する
        /// </summary>
        /// <param name="MaxNum"></param>
        /// <returns></returns>
        public static List<int> GeneratePrimesNaive(int MaxNum)
        {
            List<int> primes = new List<int>();
            primes.Add(2);
            int nextPrime = 3;
            while (nextPrime <= MaxNum)
            {
                int sqrt = (int)Math.Sqrt(nextPrime);
                bool isPrime = true;
                for (int i = 0; (int)primes[i] <= sqrt; i++)
                {
                    if (nextPrime % primes[i] == 0)
                    {
                        isPrime = false;
                        break;
                    }
                }
                if (isPrime)
                {
                    primes.Add(nextPrime);
                }
                nextPrime += 2;
            }
            return primes;
        }
        
  	public class ModInt
    {
        /// <summary>
        /// 基準となる素数
        /// </summary>
        const long BASE_NUM = 1000000007;

        public long Val { get; private set; }

        long n = 0;

        public static ModInt Zero { get; private set; } = new ModInt(0);

        public static ModInt One { get; private set; } = new ModInt(1);

        public ModInt(long n)
        {
            Val = n % BASE_NUM;
        }


        public static ModInt operator +(ModInt a, ModInt b)
        {
            if (a.Val == 0) return b;
            if (b.Val == 0) return a;

            return new ModInt(a.Val + b.Val);
        }

        public static ModInt operator -(ModInt a, ModInt b)
        {
            if (a.Val == 0) return b;
            if (b.Val == 0) return a;

            return new ModInt(a.Val - b.Val);
        }

        public static ModInt operator /(ModInt a, ModInt b)
        {
            return new ModInt(a.Val / b.Val);
        }

        public static ModInt operator *(ModInt a, ModInt b)
        {
            if (a.Val == 0) return b;
            if (b.Val == 0) return a;

            return new ModInt(a.Val * b.Val);
        }
        public static ModInt Pow(int a, int n)
        {
            if (n == 0) ModInt.ValueOf(a);

            long l = 1;

            for(int i=0;i<n;i++)
            {
                l = ( l * a ) % BASE_NUM;
            }

            return new ModInt(l);
        }

        public static ModInt ValueOf(int n)
        {
            return new ModInt(n);
        }
    }
}