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.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    public class Program
    {
        private static long mod = 1000000007;

        static void Main(string[] args)
        {
            var n = Read().Int();
            var l = new long[n];
            var r = ReadSplit();
            for (int i = 0; i < n; i++)
            {
                l[i] = r[i].Long();
            }

            var d = new Dictionary<long, int>();
            var dl = new List<Dictionary<long, int>>();
            for (int i = 0; i < n; i++)
            {
                var d2 = new Dictionary<long, int>();
                foreach (var item in GetPrimeFactors(l[i]))
                {
                    if (d2.ContainsKey(item))
                    {
                        d2[item]++;
                    }
                    else
                    {
                        d2.Add(item, 1);
                    }
                }

                dl.Add(d2);
                foreach (var item in d2)
                {
                    if (d.ContainsKey(item.Key))
                    {
                        if (d[item.Key] < item.Value)
                        {
                            d[item.Key] = item.Value;
                        }
                    }
                    else
                    {
                        d.Add(item.Key, item.Value);
                    }
                }
            }
            var ans = 0D;
            for (int i = 0; i < n; i++)
            {
                var tmp = 1D;
                foreach (var item in d)
                {
                    if (dl[i].ContainsKey(item.Key))
                    {
                        tmp *= Math.Pow(item.Key, item.Value - dl[i][item.Key]) % mod;
                    }
                    else
                    {
                        tmp *= Math.Pow(item.Key, item.Value) % mod;
                    }
                }
                ans += tmp;
                ans %= mod;
            }
            WriteRead(ans);
        }

        public static IEnumerable<long> GetPrimeFactors(long n)
        {
            long i = 2;
            long tmp = n;

            while (i * i <= n) //※1
            {
                if (tmp % i == 0)
                {
                    tmp /= i;
                    yield return i;
                }
                else
                {
                    i++;
                }
            }
            if (tmp != 1) yield return tmp;//最後の素数も返す
        }

        public static long Lcm(long a, long b)
        {
            return a / Gcd(a, b) * b;
        }
        public static long Gcd(long m, long n)
        {
            if (n == 0) return m;
            return Gcd(n, m % n);
        }

        class ModCombination
        {
            public long _mod = 1000000007;
            public int _max = 1000000;

            long[] fac;
            long[] finv;
            long[] inv;

            public ModCombination() : this(1000000007, 1000000)
            {
            }

            public ModCombination(long mod, int max)
            {
                _mod = mod;
                _max = max;
                fac = new long[max];
                finv = new long[max];
                inv = new long[max];
                fac[0] = fac[1] = 1;
                finv[0] = finv[1] = 1;
                inv[1] = 1;
                for (int i = 2; i < max; i++)
                {
                    fac[i] = fac[i - 1] * i % mod;
                    inv[i] = mod - inv[mod % i] * (mod / i) % mod;
                    finv[i] = finv[i - 1] * inv[i] % mod;
                }
            }

            public long Combination(int n, int m)
            {
                if (n < m) return 0;
                if (n < 0 || m < 0) return 0;
                return fac[n] * (finv[m] * finv[n - m] % _mod) % _mod;
            }
        }

        public static string Read()
        {
            return Console.ReadLine();
        }

        public static string[] ReadSplit()
        {
            return Console.ReadLine().Split(' ');
        }

        public static void WriteRead(object str)
        {
            Console.WriteLine(str);
            Read();
        }

        public static void Write(object str)
        {
            Console.WriteLine(str);
        }

        private static bool ChangeMin<T>(ref T a, T b) where T : IComparable
        {
            if (a.CompareTo(b) > 0)
            {
                a = b;
                return true;
            }
            return false;
        }

        private static bool ChangekMax<T>(ref T a, T b) where T : IComparable
        {
            if (b.CompareTo(a) > 0)
            {
                a = b;
                return true;
            }
            return false;
        }
    }
}


public static class Extentions
{
    public static int Int(this object obj)
    {
        return int.Parse(obj.ToString());
    }

    public static long Long(this object obj)
    {
        return long.Parse(obj.ToString());
    }

    public static decimal Decimal(this object obj)
    {
        return decimal.Parse(obj.ToString());
    }

    public static double Double(this object obj)
    {
        return double.Parse(obj.ToString());
    }

    public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct
    {
        T2 value;
        if (d.TryGetValue(key, out value))
        {
            return value;
        }
        return new T2();
    }
}