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 Java8 (OpenJDK 1.8.0) (judge verdict: Time Limit Exceeded)

//--- pE ---//
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
	public static void main (String[] args) throws java.lang.Exception {
		new Solution();
	}
}
class Solution {
	Scanner scanner;
	int inf = (int)1e9;
	int mod = (int)1e9 + 7;
	int max_a = (int)1e6 + 5;

	public Solution() {
		scanner = new Scanner(System.in);

		// scanner.nextLine();
		while (scanner.hasNext()) {
			run_case();
		}
	}
	private void run_case() {
		// scanner.nextLine();
		String line = scanner.nextLine();
		int N = Integer.parseInt(line.split("\\s+")[0]);
		// int N = Integer.parseInt(line.split("\\s+")[1]);

		int[] A = strToIntArray(scanner.nextLine());
		// int max_a = 0;
		// for (int u : A) max_a = Math.max(max_a, u);

		// prime
		// boolean[] isPrime = getPrime(max_a);
		// ArrayList<Integer> prime_idx = new ArrayList<>();
		// ArrayList<Integer> set_prime = new ArrayList<>();
		// for (int i=2; i<=max_a; i++) {
		// 	if (isPrime[i]) {
		// 		// prime_idx.add(i);
		// 		set_prime.add(i);
		// 	}
		// }
		int[] min_prime = sieve(max_a);

		// get fac prime
		// int[] cnt = new int[max_a+1];
		HashMap<Integer, Map<Integer, Integer>> mem = new HashMap<>();

		Map<Integer, Integer> cnt = new HashMap<>();

		for (int u : A) {
			if (mem.containsKey(u)) continue;

			Map<Integer, Integer> t = new HashMap<>();
			// int[] t = new int[max_a+1];
			int cur_val = u;
			while (u > 1) {
				int factor = min_prime[u];

				t.putIfAbsent(factor, 0);
				t.put(factor, t.get(factor) + 1);
				// t[factor] ++;
				u /= factor;
			}

			// ArrayList<Integer> tl = new ArrayList<>();
			// for (int v : t) tl.add(v);
			mem.put(cur_val, t);

			// for (int k=0; k<cnt.length; k++) {
				// cnt[k] = Math.max(cnt[k], t[k]);
			// }
			for (int key : t.keySet()) {
				if (!cnt.containsKey(key)) {
					cnt.put(key, t.get(key));
				} else {
					cnt.put(key, Math.max(cnt.get(key), t.get(key)) );
				}
			}
		}

		// long L = 1;
  		// for (int key : cnt.keySet()) {
		// 	for (int i=0; i<cnt.get(key); i++) {
		// 		L *= key;
		// 		L %= mod;
		// 	}
		// }

		// Map<Integer, Integer> res_cnt = new HashMap<>();
		long res = 0;
		for (int u : A) {
			long cur = 1;

			Map<Integer, Integer> t = mem.get(u);

			for (int key : cnt.keySet()) {
				int t_cnt = t.get(key) == null ? 0 : t.get(key);

				// for (int j=0; j<cnt.get(key) - t_cnt; j++) {
				// 	// tt *= key;
				// 	// tt %= mod;
				// }

				cur *= power(key, cnt.get(key) - t_cnt);
				cur %= mod;
			}
			res += cur;
			res %= mod;
		}

		System.out.println(res);
		return;
	}

	private long power(int a, int n) {
	    if (n == 0) return 1;
	    long p = power(a, n / 2) % mod;
	    p = (p * p) % mod;
	    if (n % 2 == 1) p = (p * a) % mod;
	    return p;
	}

	private long gcd(long a, long b) {
	    if (b == 0) return a;
	    else return gcd(b, a%b);
	}

	private long lcm(long a, long b) {
	    return (a / gcd(a, b) * b);
	}

	private int[] sieve(int MAX) {
		int[] prime = new int[MAX];
	    prime[0] = prime[1] = 1;
	    for (int i = 2; i < MAX; i++) {
	        if (prime[i] == 0) {
	            for (int j = i * 2; j < MAX; j += i) {
	                if (prime[j] == 0) {
	                    prime[j] = i;
	                }
	            }
	            prime[i] = i;
	        }
	    }
		return prime;
	}

	private boolean[] getPrime(int n) {
	    boolean[] prime = new boolean[n + 1];
	    Arrays.fill(prime, true);
	    prime[0] = prime[1] = false;

	    for (int i=2; i<=Math.sqrt(n); i++) {
	        if (prime[i]) {
	            for (int j=2; i*j <= n; j++) {
	                prime[i*j] = false;
	            }
	        }
	    }
	    return prime;
	}

	private Set<Integer> getisNotPrime(int n) {
		Set<Integer> res = new HashSet<>();
		res.add(0);
		res.add(1);

	    boolean[] prime = new boolean[n + 1];
	    Arrays.fill(prime, true);
	    prime[0] = prime[1] = false;

	    for (int i=2; i<=Math.sqrt(n); i++) {
	        if (prime[i]) {
	            for (int j=2; i*j <= n; j++) {
	                prime[i*j] = false;
					res.add(i*j);
	            }
	        }
	    }

	    return res;
	}


	private int[] strToIntArray(String str) {
	    String[] vals = str.split("\\s+");
	    int sz = vals.length;
	    int[] res = new int[sz];
	    for (int i=0; i<sz; i++) {
	        res[i] = Integer.parseInt(vals[i]);
	    }
	    return res;
	}
}
class Spell {
	public int power, cost;
	public Spell(int power, int cost) {
		this.power = power;
		this.cost = cost;
	}
}