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: Accepted)

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

namespace Contest
{
    partial class Program
    {
        static void Main(string[] args)
        {
            ABC152_E();
        }
        #region ABC152
        static void ABC152_A()
        {
            var nm = ReadIntN();
            Console.WriteLine(nm[0] == nm[1] ? "Yes" : "No");
        }
        static void ABC152_B()
        {
            var ab = ReadIntN();
            var A = ab[0];
            var B = ab[1];
            Console.WriteLine(A < B ? String.Join("", Enumerable.Repeat(A, B)) : String.Join("", Enumerable.Repeat(B, A)));
        }
        static void ABC152_C()
        {
            var N = ReadInt();
            var P = ReadIntN();
            int min = P[0];
            int count = 0;
            for (int i = 0; i < N; ++i)
            {
                if (min >= P[i])
                {
                    count += 1;
                    min = P[i];
                }
            }
            Console.WriteLine(count);
        }
        static void ABC152_D()
        {
            var N = ReadInt();
            long[,] count = new long[10, 10];
            for (int i = 1; i <= N; ++i)
            {
                var A1 = i;
                while (A1 > 9) { A1 /= 10; }
                var A0 = i % 10;
                count[A1, A0]++;
            }
            Console.WriteLine(Enumerable.Range(1, 9).Select(i => Enumerable.Range(1, 9).Select(j => count[i, j] * count[j, i]).Sum()).Sum());
        }
        static void ABC152_E()
        {
            var N = ReadInt();
            var A = ReadIntN();

            Dictionary<long, int> lcm = new Dictionary<long, int>();
            foreach(var a in A)
            {
                var f = Util.Factorize(a);
                foreach(var kvp in f)
                {
                    if (!lcm.ContainsKey(kvp.Key))
                    {
                        lcm.Add(kvp.Key, 0);
                    }
                    lcm[kvp.Key] = Math.Max(lcm[kvp.Key], kvp.Value);
                }
            }

            long mult = 1;
            foreach(var kvp in lcm)
            {
                for (int i = 0; i < kvp.Value; ++i)
                {
                    mult = (mult * kvp.Key) % Util.P;
                }
            }
            long sum = 0;
            foreach(var a in A)
            {
                sum += (mult * Util.Inverse(a, Util.P)) % Util.P;
            }
            sum %= Util.P;
            Console.WriteLine(sum);
        }
        #endregion
        class Util
        {
            public static readonly long P = 1000000007;

            public static Dictionary<long,int> Factorize(long x)
            {
                var dict = new Dictionary<long, int>();
                long minp = 2;
                while (x > 1)
                {
                    bool ok = false;
                    for(long p = minp; p * p <= x; ++p)
                    {
                        if (x % p == 0)
                        {
                            if (!dict.ContainsKey(p))
                            {
                                dict.Add(p, 0);
                            }
                            dict[p]++;
                            minp = p;
                            x /= p;
                            ok = true;
                            break;
                        }
                    }
                    if (!ok)
                    {
                        if (!dict.ContainsKey(x)) { dict.Add(x, 0); }
                        dict[x]++;
                        break;
                    }
                }
                return dict;
            }
            public static long Inverse(long a, long p)
            {
                long b = p, c = 1, d = 0, e = 0, f = 0;
                while (b != 0)
                {
                    e = a / b;
                    f = b; b = a - e * b; a = f;
                    f = d; d = c - e * d; c = f;
                }
                c %= p;
                return c + (c < 0 ? p : 0);
            }
            public static long[] Facts(int n, long p)
            {
                var facts = new long[n + 1];
                facts[0] = 1;
                for (int i = 1; i <= n; ++i)
                {
                    facts[i] = (i * facts[i - 1]) % p;
                }
                return facts;
            }
        }


        static string ReadStr()
        {
            return Console.ReadLine();
        }
        static string[] ReadStrN()
        {
            return Console.ReadLine().Split(' ');
        }
        static int ReadInt()
        {
            return Convert.ToInt32(Console.ReadLine());
        }
        static int[] ReadIntN()
        {
            return Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray();
        }
        static long ReadLong()
        {
            return Convert.ToInt64(Console.ReadLine());
        }
        static long[] ReadLongN()
        {
            return Console.ReadLine().Split(' ').Select(s => Convert.ToInt64(s)).ToArray();
        }
        static Tuple<long, long>[]  ReadTupleLong(int n)
        {
            List<Tuple<long, long>> list = new List<Tuple<long, long>>();
            for (int i = 0; i < n; ++i)
            {
                var ab = ReadLongN();
                list.Add(new Tuple<long, long>(ab[0], ab[1]));
            }
            return list.ToArray();
        }
    }
}