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: Time Limit Exceeded)

use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
use std::collections::HashMap;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn gcd(a: u64, b: u64) -> u64{
    if b == 0{
        return a;
    }

    return gcd(b, a%b);
}

fn lcm(a: &HashMap<u64, u64>, b:  &HashMap<u64, u64>) -> HashMap<u64, u64>{
    let mut res  = a.clone();

    for (key, val) in b.iter(){
        let cur_val = res.entry(*key).or_insert(*val);
        if *cur_val < *val{
            *cur_val = *val;
        }
    }
    return res;
}

fn ext(x: u64) -> HashMap<u64, u64>{
    if x == 1{
        return HashMap::new();
    }
    let mut x = x;
    let mut hash = HashMap::new() ;
    for div in 2..(x as f64).sqrt().ceil() as u64+1{
        while x%div == 0{
            *hash.entry(div).or_insert(0) += 1;
            x /= div;
        }
    }
    *hash.entry(x).or_insert(0) += 1;
    return hash;

}

fn get_b(lcm_a: &HashMap<u64, u64>, a: &HashMap<u64, u64>) -> u64{
    let mut res = lcm_a.clone();

    for (key, value) in res.iter_mut(){
        if let Some(x) = a.get(key){
            *value -= *x;
        }
        //*value -= a.get(key).unwrap();
    }

    let mut ans = 1;
    for (key, value) in res.iter(){
        for i in 0..*value{
            ans *= *key;
            ans %= 1_000_000_007;
        }
    }

    return ans;
}

fn main(){
    let n: usize = read_as_vec::<usize>()[0];
    let a = read_as_vec::<u64>();
    let mut pa: Vec<HashMap<u64, u64>> = vec![];

    for &elem in &a{
        pa.push(ext(elem));
     }
    let mut lcm_a = pa[0].clone();

    for i in 0..pa.len(){
        lcm_a = lcm(&lcm_a, &pa[i]);
    }

    let mut ans = 0;
    for i in 0..pa.len(){
        let b = get_b(&lcm_a, &pa[i]);
        ans += b;
        ans %= 1_000_000_007;
    }

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