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 (GCC 9.2.1) (judge verdict: Wrong Answer)

#include <stdio.h>

#define Mod 1000000007

long long div_mod(long long x, long long y, long long z)
{
	if (x % y == 0) return x / y;
	else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}

void merge_sort(int x[], int n)
{
	static int y[100001] = {};
	if (n == 1) return;
	merge_sort(&(x[0]), n/2);
	merge_sort(&(x[n/2]), (n+1)/2);
	
	int i, p, q;
	for (i = 0, p = 0, q = n/2; i < n; i++) {
		if (p >= n/2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p] < x[q])? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

int prime[10000];

int enum_primes(int n)
{
	int i, k, p;
	for (p = 2, k = 0; p < n; p++) {
		for (i = 2; i * i <= p; i++) if (p % i == 0) break;
		if (i * i > p) prime[k++] = p;
	}
	return k;
}

int factorize(int n, int p[], int m[])
{
	int i, k;
	for (i = 0, k = 0; n > 1 && prime[i] <= 1000; i++) {
		if (n % prime[i] != 0) continue;
		p[k] = i;
		for (m[k] = 0; n % prime[i] == 0; m[k]++, n /= prime[i]);
		k++;
	}
	if (n > 1) {
		p[k] = n;
		m[k++] = 1;
	}
	return k;
}

int main()
{
	int i, N, A[100001];
	scanf("%d", &N);
	for (i = 0; i < N; i++) scanf("%d", &(A[i]));
	merge_sort(A, N);
	
	int j, k = enum_primes(1000), l, p[10000], m[10000], lcm[10000] = {};
	prime[k] = 10000;
	for (i = 0; i < N; i++) {
		l = factorize(A[i], p, m);
		for (j = 0; j < l && p[j] < k; j++) if (lcm[p[j]] < m[j]) lcm[p[j]] = m[j];
		if (j < l) {
			prime[k] = p[j];
			lcm[k++] = 1;
		}
	}
	
	long long L = 1, ans = 0;
	for (i = 0; i < k; i++) {
		for (j = 0; j < lcm[i]; j++) L = L * prime[i] % Mod;
	}
	for (i = 0; i < N; i++) ans += div_mod(L, (long long)A[i], Mod);
	
	printf("%lld\n", ans % Mod);
	fflush(stdout);
	return 0;
}