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# (.NET Core 3.1.201) (judge verdict: Accepted)

using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass : Scanner
{
    static void Main()
    {
        int N = RInt();
        var A = RLongs();

        var dic = new Counter<long>();
        for (int i = 0; i < N; i++)
        {
            var cnt = new Counter<long>();
            long num = A[i];
            for (int j = 2; j * j <= A[i]; j++)
            {
                while (num % j == 0)
                {
                    num /= j;
                    cnt[j]++;
                }
            }
            if (num != 1) cnt[num]++;
            foreach (var item in cnt)
            {
                dic[item.Key] = Max(dic[item.Key], item.Value);
            }
        }

        Modular lcm = 1;
        foreach (var item in dic)
        {
            lcm *= Modular.Pow(item.Key, item.Value);
        }
        Modular ans = 0;
        for (int i = 0; i < N; i++)
        {
            ans += lcm / A[i];
        }
        WriteLine((int)ans);
    }
}

class Modular
{
    private const int M = 1000000007;
    private const int arysize = 2000001;
    private long value;
    public Modular(long value = 0) { this.value = value; }
    public override string ToString() { return value.ToString(); }
    public static implicit operator Modular(long a)
    {
        var m = a % M;
        return new Modular((m < 0) ? m + M : m);
    }
    public static Modular operator +(Modular a, Modular b)
    => a.value + b.value;
    public static Modular operator -(Modular a, Modular b)
    => a.value - b.value;
    public static Modular operator *(Modular a, Modular b)
    => a.value * b.value;
    public static Modular Pow(Modular a, long n)
    {
        Modular ans = 1;
        for (; n > 0; n >>= 1, a *= a)
        {
            if ((n & 1) == 1) ans *= a;
        }
        return ans;
    }
    public static Modular operator /(Modular a, Modular b)
    {
        return a * Pow(b, M - 2);
    }
    private static int[] facs = new int[arysize];
    private static int facscount = -1;

    public static Modular Fac(int n)   //階乗
    {
        facs[0] = 1;
        while (++facscount <= n)
        {
            facs[facscount + 1] = (int)(Math.BigMul(facs[facscount], facscount + 1) % M);
        }
        return facs[n];
    }
    public static Modular Fac(int r, int n)//記録しない階乗
    {
        int temp = 1;
        for (int i = r; i <= n; i++)
        {
            temp = (int)(Math.BigMul(temp, i) % M);
        }
        return temp;
    }
    public static Modular Ncr(int n, int r) //nCr
    {
        return (n < r) ? 0
             : (n == r) ? 1
                        : (Math.Max(n, r) <= arysize) ? Fac(n) / (Fac(r) * Fac(n - r))
                            : Fac(n - r + 1, n) / Fac(r);
    }
    public static explicit operator int(Modular a)
    {
        return (int)a.value;
    }
}
class Counter<T> //valueをlongに限定したDictionary キーがない値を参照してもエラーしない 初期化 0
{
    private Dictionary<T, long> dic;
    public Counter()
    {
        dic = new Dictionary<T, long>();
    }
    public long this[T item]
    {
        set
        {
            dic.TryGetValue(item, out long v);
            dic[item] = value;
        }
        get
        {
            dic.TryGetValue(item, out long v);
            return v;
        }
    }
    public IEnumerator<KeyValuePair<T, long>> GetEnumerator()
    {
        foreach (var item in dic)
        {
            yield return item;
        }
    }
    public bool ContainsKey(T item) => dic.ContainsKey(item);
    public Dictionary<T, long>.KeyCollection Keys => dic.Keys;
    public Dictionary<T, long>.ValueCollection Values => dic.Values;
}


class Scanner
{
    public static string RString() => Console.ReadLine();
    public static int RInt() => ReadTuple<int>();
    public static long RLong() => ReadTuple<long>();
    public static double RDouble() => ReadTuple<double>();

    public static string[] RStrings() => Console.ReadLine().Split();
    public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
    public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
    public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse);
    public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray();
    //public static string[] RStrings(Func<string, string> func) => Console.ReadLine().Split().Select(func).ToArray();

    public static T1 ReadTuple<T1>()
    {
        var r = RString();
        var r1 = (T1)Convert.ChangeType(r, typeof(T1));
        return r1;
    }
    public static (T1, T2) ReadTuple<T1, T2>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        return (r1, r2);
    }
    public static (T1, T2, T3) ReadTuple<T1, T2, T3>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        return (r1, r2, r3);
    }
    public static (T1, T2, T3, T4) ReadTuple<T1, T2, T3, T4>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        var r4 = (T4)Convert.ChangeType(r[3], typeof(T4));
        return (r1, r2, r3, r4);
    }
}