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

#include <bits/stdc++.h>
using namespace std;

#define mp make_pair
#define pb push_back

#define int int64_t

const int MOD = 1e9+7;

int mpow(int a,int b) {
	if(b==0)
		return 1;
	int temp= mpow(a,b/2);
	temp*=temp;
	temp%=MOD;
	if(b&1) {
		return (a*temp)%MOD;
	}
	else return temp;
} 

int modinv(int a) {
	return mpow(a, MOD-2);
} 

int cp[1000001];
int pr[1000001];

int32_t main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int32_t n;
    cin>>n;
    int32_t arr[n];
    int32_t maxa=0;
    for(int i=0;i<n;i++)
    {	cin>>arr[i];
    	maxa=max(maxa, arr[i]);
    }
    int prcnt=0;
    for(int i=2;i*i<=maxa;i++) {
    	if(cp[i]==0)
    	{
    		for(int j=2*i;j<1000001;j+=i)
    			cp[j]=1;
    		//pr.pb(i);
    		//cout<<i<<" ";
    	}
    }
    //cout<<pr.size()<<"\n";
    //cout<<cp[2]<<" ";
    for(int i=2;i<=maxa;i++) {
    	if(cp[i]==0)
    	{
    		pr[prcnt]=i;
    		prcnt++;
    	}
    }
    int lcm=1;
    //cout<<pr.size()<<"\n";
    map<int,int> cnt;
    for(int j=0;j<n;j++) {
    	if(lcm%arr[j]==0)
    		continue;
    	int t=arr[j];
    	for(int i=0;i<prcnt;i++) {
    		if(pr[i]*pr[i]>t)
    			break;
    		int f2=t/pr[i];
    		int c=0;
    		//if(pr[i]>maxa)
    		while(t%(pr[i])==0) {
    			t/=pr[i];
    			c++;
    		}
    		int c2=0;
    		if(cp[f2]==0&&f2>1)
    		while((t%(f2))==0) {
    			t/=f2;
    			c2++;
    		}
    		if(c>cnt[pr[i]])
    		{
    			lcm*=mpow(pr[i], c-cnt[pr[i]]);
    			lcm%=MOD;
    			cnt[pr[i]]=c;
    		}
    		if(cp[f2]&&c2>cnt[f2]) {
    			lcm*=mpow(f2,c2-cnt[f2]);
    			lcm%=MOD;
    			cnt[f2]=c2;
    		}
    	}
    }

    int ans=0;
    for(int i=0;i<n;i++) {
    	ans+=lcm*modinv(arr[i]);
    	if(ans>MOD);
    	ans%=MOD;
    }

    cout<<ans;

	return 0;
}