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.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class E
{
	public static void Main() => (new Solver()).Solve();
}

public class Solver
{
	public void Solve()
	{
		long mod = (long)1e9 + 7;
		int N = GetInt();
		var A = GetLongs(N);

		var primes = sieve(A.Max());
		var cnt = Enumerable.Range(0, N).Select(x => factorization(primes, A[x])).ToArray();
		var max = new Dictionary<long, long>();
		for(int i = 0; i < N; i++)
		{
			foreach(long p in cnt[i].Keys)
			{
				long c = 0;
				max.TryGetValue(p, out c);
				max[p] = Max(c, cnt[i][p]);
			}
		}

		long ans = 0;
		for(int i = 0; i < N; i++)
		{
			long B = 1;
			foreach(long p in max.Keys)
			{
				long c = 0;
				cnt[i].TryGetValue(p, out c);
				B = (B * modPow(mod, p, max[p] - c)) % mod;
			}
			ans = (ans + B) % mod;
		}
		WriteLine(ans);
	}

	private List<long> sieve(long N)
	{
		var primeList = new List<long>();
		bool[] isPrime = new bool[(int)N + 1];
		for(long i = 2; i <= N; i++)
			isPrime[i] = true;

		for(long i = 2; i <= N; i++)
		{
			if(isPrime[i])
			{
				primeList.Add(i);
				for(long j = 2 * i; j <= N; j += i)
					isPrime[j] = false;
			}
		}

		return primeList;
	}

	private Dictionary<long, long> factorization(List<long> primes, long x)
	{
		var cnt = new Dictionary<long, long>();
		long rest = x;
		foreach(var p in primes)
		{
			while(rest % p == 0)
			{
				rest /= p;
				long c = 0;
				cnt.TryGetValue(p, out c);
				cnt[p] = c + 1;
			}
		}
		return cnt;
	}

	private long modPow(long mod, long x, long y)
	{
		long xx = x;
		long pow = y;
		long v = 1;
		while(pow > 0)
		{
			if((pow & 1) == 1)
				v = (v * xx) % mod;

			xx = (xx * xx) % mod;
			pow >>= 1;
		}
		return v;
	}
}

public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => Enumerable.Range(0, (int)N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(long N) => Enumerable.Range(0, (int)N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDouble()).ToArray();
	public static decimal[] GetDecimals(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDecimal()).ToArray();
	public static string[] GetStrings(long N) => Enumerable.Range(0, (int)N).Select(_ => GetString()).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) < 0)
			x = y;
	}

	public static void chmin<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) > 0)
			x = y;
	}

	public static void swap<T>(ref T x, ref T y)
	{
		T tmp = x;
		x = y;
		y = tmp;
	}
}