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 Java (OpenJDK 11.0.6) (judge verdict: Accepted)

import java.util.*;

public class Main {
    static final int MOD = 1000000007;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<HashMap<Integer, Integer>> list = new ArrayList<>();
		HashMap<Integer, Integer> all = new HashMap<>();
		for (int i = 0; i < n; i++) {
		    HashMap<Integer, Integer> map = getMap(sc.nextInt());
		    for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
		        int key = entry.getKey();
		        int value = entry.getValue();
		        if (!all.containsKey(key) || all.get(key) < value) {
		            all.put(key, value);
		        }
		    }
		    list.add(map);
		}
		long[] tmp = new long[n];
		Arrays.fill(tmp, 1L);
		for (Map.Entry<Integer, Integer> entry : all.entrySet()) {
		    int key = entry.getKey();
		    int value = entry.getValue();
		    for (int i = 0; i < n; i++) {
		        if (list.get(i).containsKey(key)) {
		            tmp[i] *= pow(key, value - list.get(i).get(key));
		        } else {
		            tmp[i] *= pow(key, value);
		        }
		        tmp[i] %= MOD;
		    }
		}
		long ans = 0;
		for (long x : tmp) {
		    ans += x;
		    ans %= MOD;
		}
		System.out.println(ans);
   }
   
   static long pow(long x, long y) {
       if (y == 0) {
           return 1;
       } else if (y % 2 == 0) {
           return pow(x * x % MOD, y / 2);
       } else {
           return pow(x, y - 1) * x % MOD;
       }
   }
    
    static HashMap<Integer, Integer> getMap(int x) {
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 2; i <= Math.sqrt(x); i++) {
            while(x % i == 0) {
                if (map.containsKey(i)) {
                    map.put(i, map.get(i) + 1);
                } else {
                    map.put(i, 1);
                }
                x /= i;
            }
        }
        if (x > 1) {
            if (map.containsKey(x)) {
                map.put(x, map.get(x) + 1);
            } else {
                map.put(x, 1);
            }
        }
        return map;
    }
}