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;
using System.Collections.Generic;
using System.Linq;
using static Common;
using static Constans;

public static class Constans
{
    public const long Mod = (long)1e9 + 7;
}

public struct ModInt
{
    public long Num;

    public ModInt(long num)
    {
        Num = num;
    }

    // x^n
    public static long Power(long x, long n)
    {
        long pow = 1;
        while (n > 0)
        {
            if (n % 2 == 0)
            {
                x *= x;
                x %= Mod;
                n /= 2;
            }
            else
            {
                pow *= x;
                pow %= Mod;
                n--;
            }
        }

        return pow;
    }

    public static ModInt GetInv(long f)
    {
        // フェルマーの小定理 a^(-1) = a^(mod-2)
        return new ModInt(Power(f, Mod - 2));
    }

    public ModInt GetInv()
    {
        return GetInv(Num);
    }

    public override string ToString()
    {
        return Num.ToString();
    }

    public static ModInt operator +(ModInt l, ModInt r)
    {
        l.Num += r.Num;
        if (l.Num >= Mod)
        {
            l.Num -= Mod;
        }
        return l;
    }

    public static ModInt operator -(ModInt l, ModInt r)
    {
        l.Num -= r.Num;
        if (l.Num < 0)
        {
            l.Num += Mod;
        }
        return l;
    }

    public static ModInt operator *(ModInt l, ModInt r)
    {
        return new ModInt(l.Num * r.Num % Mod);
    }

    public static implicit operator ModInt(long n)
    {
        n %= Mod;
        if (n < 0)
        {
            n += Mod;
        }
        return new ModInt(n);
    }
}

public class Prime
{
    BitArray Sieve;
    // Sieve of Eratosthenes
    public void Init(int max)
    {
        Sieve = new BitArray(max + 1);
        var end = (int)(Math.Sqrt(max) + 0.1);
        Sieve.Set(1, true);
        for (int i = 2; i <= end; i++)
        {
            if (!Sieve.Get(i))
            {
                for (int j = i * 2; j <= max; j += i)
                {
                    Sieve.Set(j, true);
                }
            }
        }
    }

    public bool IsPrime(int n)
    {
        return !Sieve.Get(n);
    }

    public int[] GetPrimes(int n)
    {
        return Enumerable.Range(2, n - 1).Where(i => !Sieve.Get(i)).ToArray();
    }
}

public static class PrimeFactorize
{
    static List<long> Factorize(long n, IEnumerable<int> primes)
    {
        var factor = new List<long>();
        foreach (var p in primes)
        {
            while (n % p == 0)
            {
                factor.Add(p);
                n /= p;
            }
        }
        if (n > 1)
        {
            factor.Add(n);
        }
        return factor;
    }

    static Dictionary<long, int> FactorToDict(IEnumerable<long> factor)
    {
        var dict = new Dictionary<long, int>();

        foreach (var f in factor)
        {
            if (!dict.ContainsKey(f))
            {
                dict[f] = 0;
            }
            dict[f]++;
        }

        return dict;
    }

    public static void Init(int n)
    {
        prime = new Prime();
        var max = (int)(Math.Sqrt(n) + 1);
        prime.Init(max);
    }

    static Prime prime;
    // 要素を各個数で表す
    public static Dictionary<long, int> Factorize(long n)
    {
        var max = (int)(Math.Sqrt(n) + 1);
        var primes = prime.GetPrimes(max);
        return FactorToDict(Factorize(n, primes));
    }
}

public static class Common
{
    public static Dictionary<long, int> LCM(Dictionary<long, int> m, Dictionary<long, int> n)
    {
        var lcm = m.ToDictionary(x => x.Key, x => x.Value);
        foreach (var key in n.Keys)
        {
            if (lcm.ContainsKey(key))
            {
                var max = Math.Max(lcm[key], n[key]);
                lcm[key] = max;
            }
            else
            {
                lcm[key] = n[key];
            }
        }

        return lcm;
    }

    public static Dictionary<long, int> Div(Dictionary<long, int> m, Dictionary<long, int> n)
    {
        var result = m.ToDictionary(x => x.Key, x => x.Value);
        foreach (var nf in n)
        {
            result[nf.Key] -= nf.Value;
            if (result[nf.Key] == 0)
            {
                result.Remove(nf.Key);
            }
        }
        return result;
    }
    public static ModInt GetModint(Dictionary<long, int> m)
    {
        var i = new ModInt(1);
        foreach (var mf in m)
        {
            i *= ModInt.Power(mf.Key, mf.Value);
        }
        return i;
    }
}

public class Solution
{
    public static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        var A = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

        PrimeFactorize.Init(A.Max());
        var af = A.Select(a => PrimeFactorize.Factorize(a)).ToArray();
        var lcm = af.First();
        foreach (var a in af)
        {
            lcm = LCM(lcm, a);
        }

        ModInt sum = 0;
        foreach (var a in af)
        {
            var b = GetModint(Div(lcm, a));
            sum += b;
        }

        Console.WriteLine(sum);
    }
}