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)

// This code is generated by [cargo-atcoder](https://github.com/tanakh/cargo-atcoder)
// Original source code:
/*
#![allow(unused_imports)]
use itertools::Itertools;
use num::integer::lcm;
use proconio::{input, marker::*};
use std::cmp::*;
use std::collections::*;
use superslice::*;

const MOD: usize = 1_000_000_007;

fn main() {
    input! {
        a:[usize]
    }

    let mut primes: HashMap<usize, usize> = HashMap::new();
    for &i in &a {
        let factors = prime_factorize(i);
        for (k, v) in factors {
            let ex = primes.entry(k).or_insert(0);
            *ex = max(*ex, v);
        }
    }

    let mut lcm = 1;
    for (k, v) in primes {
        lcm = lcm * mod_pow(k, v, MOD) % MOD;
    }

    let mut sum = 0;
    for i in a {
        sum = (sum + lcm * inv(i, MOD)) % MOD;
    }

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

fn prime_factorize(n: usize) -> Vec<(usize, usize)> {
    let mut n = n;
    let mut res = vec![];
    let mut a = 2;

    while a * a <= n {
        if n % a != 0 {
            a += 1;
            continue;
        }

        let mut count = 0;
        while n % a == 0 {
            count += 1;
            n /= a;
        }

        res.push((a, count));
        a += 1;
    }

    if n != 1 {
        res.push((n, 1));
    }

    res
}

// aのn乗を求める。繰り返し二乗法によりO(logN)で計算できる
fn mod_pow(a: usize, n: usize, mod_n: usize) -> usize {
    if n == 0 {
        return 1;
    }

    let mut res = mod_pow(a, n / 2, mod_n);
    res = res * res % mod_n;

    if n % 2 == 1 {
        res = res * a % mod_n;
    }

    res
}

// mod_nにおける逆元(1/x)を求める。modで割り算するときは逆元をかける。
// フェルマーの小定理 x^(p-1) ≡ 1 (mod p: pは素数)より
fn inv(a: usize, mod_n: usize) -> usize {
    mod_pow(a, mod_n - 2, mod_n)
}

// nCkを求める
fn choose(n: usize, k: usize, md: usize) -> usize {
    let mut res1 = 1;
    let mut res2 = 1;
    let mut i = 1;
    while i <= k {
        res1 = (res1 * (n - (i - 1))) % md;
        res2 = (res2 * i) % md;
        i += 1;
    }

    res1 * inv(res2, md) % md
}
*/

fn main() {
    let exe = "/tmp/binDFBF5EFA";
    std::io::Write::write_all(&mut std::fs::File::create(exe).unwrap(), &decode(BIN)).unwrap();
    std::fs::set_permissions(exe, std::os::unix::fs::PermissionsExt::from_mode(0o755)).unwrap();
    std::process::exit(std::process::Command::new(exe).status().unwrap().code().unwrap())
}

fn decode(v: &str) -> Vec<u8> {
    let mut ret = vec![];
    let mut buf = 0;
    let mut tbl = vec![64; 256];
    for i in 0..64 { tbl[TBL[i] as usize] = i as u8; }
    for (i, c) in v.bytes().filter_map(|c| { let c = tbl[c as usize]; if c < 64 { Some(c) } else { None } }).enumerate() {
        match i % 4 {
            0 => buf = c << 2,
            1 => { ret.push(buf | c >> 4); buf = c << 4; }
            2 => { ret.push(buf | c >> 2); buf = c << 6; }
            3 => ret.push(buf | c),
            _ => unreachable!(),
        }
    }
    ret
}

const TBL: &'static [u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const BIN: &'static str = "<base64-encoded ELF executable removed>";