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: Wrong Answer)

use std::cmp::*;
use std::collections::*;
use std::io::*;
use std::str::*;

fn read<T: FromStr>(s: &mut StdinLock) -> Option<T> {
    let s = s
        .by_ref()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

fn update_primes(i: usize, primes: &mut HashMap<usize, usize>) {
    if primes.contains_key(&i) {
        let x = primes.get_mut(&i).unwrap();
        *x += 1;
    } else {
        primes.insert(i, 1);
    }
}

fn trial_division(mut n: usize) -> HashMap<usize, usize> {
    let mut primes = HashMap::new();
    let mut i = 2;

    //  n を root n 以下の整数で割り切れるまで割っていく
    while i * i <= n {
        while n % i == 0 {
            n /= i;
            update_primes(i, &mut primes);
        }
        i += 1;
    }

    // 最後にnが素数になっている場合はそれ自身も素因数に含めて終了
    if n > 1 {
        update_primes(n, &mut primes);
    }
    primes
}
fn main() {
    let s = stdin();
    let mut s = s.lock();
    let n: usize = read(&mut s).unwrap();
    let mut a_array = Vec::new();
    let mut max_a = 0;
    for _ in 0..n {
        let a: i32 = read(&mut s).unwrap();

        a_array.push(a);
        max_a = max(max_a, a);
    }

    let mut p_array = Vec::new();
    let mut p_set = HashSet::new();
    for i in 0..n {
        let p = trial_division(a_array[i] as usize);
        let set = p.keys().cloned().collect();
        p_set = p_set.union(&set).cloned().collect();

        p_array.push(p);
    }

    let mut lcm_array = Vec::new();
    for p in &p_set {
        let mut lcm = 0;
        for i in 0..n {
            if p_array[i].contains_key(&p) {
                lcm = max(lcm, *(p_array[i].get(&p).unwrap()));
            }
        }
        lcm_array.push(lcm);
    }
    //println! {"p: {:?}", p_set};
    //println!("lcm: {:?}", lcm_array);
    let mut b_array = Vec::new();
    for i in 0..n {
        let mut b = 1;
        //println!("hoge {}", a_array[i]);
        for (pi, p) in p_set.iter().enumerate() {
            if p_array[i].contains_key(&p) {
                //println!("{}, {}, {}", p, lcm_array[pi], p_array[i].get(&p).unwrap());
                let x = lcm_array[pi] - p_array[i].get(&p).unwrap();
                //println!("  {} ** {}", p, x);
                b *= p.pow(x as u32);
            } else {
                //println!("{}, {}, {}", p, lcm_array[pi], 0);
                //println!("  {} ** {}", p, lcm_array[pi]);

                b *= p.pow(lcm_array[pi] as u32);
            }
        }
        b_array.push(b);
    }
    //println!("{:?}", b_array);
    let mut res = b_array.iter().fold(0, |sum, a| sum + a);
    if res > (10u32.pow(9u32) + 7u32) as usize {
        res = res % (10u32.pow(9u32) + 7) as usize;
    }
    println!("{}", res);

    //println!("{}", b_array.iter().sum());
}