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 Rust (1.15.1) (judge verdict: Accepted)

pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

use std::collections::HashMap;

const R: u64 = 1000000007;

fn pow(n: u64, p: u64, r: u64) -> u64 {
    let mut ret;

    if p == 0 {
        ret = 1;
    } else {
        ret = pow(n, p / 2, r);
        ret = ret * ret % r;
        if p % 2 == 1 {
            ret = ret * n % r;
        }
    }

    ret
}

fn fact(hm: &mut HashMap<u64, u64>, mut a: u64) {
    while a != 1 {
        let mid = (a as f64).sqrt() as u64;
        let mut k = a;
        let mut v = *hm.get(&a).unwrap_or(&0);
        for n in 2..mid + 1 {
            if a % n == 0 {
                k = n;
                v = *hm.get(&n).unwrap_or(&0);
                break;
            }
        }
        if k == a {
            a = 1;
        } else {
            a /= k;
        }
        hm.insert(k, v + 1);
    }
}

fn union(hm: &mut HashMap<u64, u64>, tmp: &HashMap<u64, u64>) {
    for (k, v1) in tmp.iter() {
        let mut v = *hm.get(k).unwrap_or(&0);
        if *v1 > v {
            v = *v1;
        }
        hm.insert(*k, v);
    }
}

fn lcm(a: &Vec<u64>, n: usize) -> u64 {
    let mut hm = HashMap::new();

    for i in 0..n {
        let mut tmp = HashMap::new();
        fact(&mut tmp, a[i]);
        union(&mut hm, &tmp);
    }

    let mut ret = 1;

    for (k, v) in hm.iter() {
        ret = ret * pow(*k, *v, R) % R;
    }

    ret
}

fn main() {
    let n: usize = read();
    let a: Vec<u64> = read_vec();

    let tmp1 = lcm(&a, n);

    let mut tmp2 = 0;
    for i in 0..n {
        tmp2 = (tmp2 + pow(a[i], R - 2, R)) % R;
    }

    let ans = tmp1 * tmp2 % R;

    println!("{}", ans);
}