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-mcs 6.8.0.105) (judge verdict: Time Limit Exceeded)

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

static class Program
{
    const int M = 1000000007;

    static Dictionary<int, int> Factorize(int a)
    {
        var dict = new Dictionary<int, int>();
        for (int i = 2; i <= 1000 && a > 1; ++i)
        {
            int cnt = 0;
            while ((a % i) == 0)
            {
                a /= i;
                ++cnt;
            }
            if (cnt > 0) { dict[i] = cnt; }
        }
        if (a > 1) { dict[a] = 1; }
        return dict;
    }

    static int Pow(int a, int b)
    {
        switch (b)
        {
        case 0:
            return 1;
        case 1:
            return a;
        default:
            int x = Pow(a, b / 2);
            int y = (b % 2 != 0) ? Pow(a, (b + 1) / 2) : x;
            return (int)(Math.BigMul(x, y) % M);
        }
    }

    static int Solve(int N, int[] A)
    {
        var lcm = new Dictionary<int, int>();
        var B = Array.ConvertAll(A, Factorize);
        foreach (var b in B)
        {
            foreach (var pair in b)
            {
                if (!lcm.ContainsKey(pair.Key) || lcm[pair.Key] < pair.Value)
                {
                    lcm[pair.Key] = pair.Value;
                }
            }
        }
        long sum = 0;
        foreach (var b in B)
        {
            long prod = 1;
            foreach (var pair in lcm)
            {
                int value = b.ContainsKey(pair.Key) ? b[pair.Key] : 0;
                prod *= Pow(pair.Key, pair.Value - value);
                prod %= M;
            }
            sum += prod;
            sum %= M;
        }
        return (int)sum;
    }

    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        var A = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        Console.WriteLine(Solve(N, A));
    }
}