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)

// This code is generated by [cargo-atcoder](https://github.com/tanakh/cargo-atcoder)
// Original source code:
/*
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::collections::HashMap;

const MO: u64 = 1_000_000_007;
const LIM: u64 = 1_000_010;

fn factor(n: usize) -> HashMap<usize, usize> {
    let mut fac = HashMap::new();
    let mut m = n;
    for p in 2..m + 1 {
        if m < p {
            break;
        }
        while m % p == 0 {
            let e = fac.entry(p).or_insert(0);
            *e += 1;
            m /= p;
        }
    }
    fac
}

fn powmod(x: u64, e: usize) -> u64 {
    let mut v = 1;
    let mut x = x;
    let mut e = e;
    while e > 0 {
        if e % 2 == 1 {
            v = v * x % MO;
        }
        e /= 2;
        x = x * x % MO;
    }
    v % MO
}

fn value(fac: &HashMap<usize, usize>) -> u64 {
    let mut res = 1;
    for (p, e) in fac.iter() {
        res = res * powmod(*p as u64, *e) % MO;
    }
    res
}

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

    let mut inv = vec![0, 1];
    for i in 2..LIM {
        inv.push(MO - MO / i * inv[(MO % i) as usize] % MO);
    }

    let mut factors = vec![];
    for k in a {
        factors.push(factor(k));
    }

    let mut lcm = HashMap::new();
    for fac in factors.iter() {
        for (p, e) in fac.iter() {
            let lcm_e = lcm.entry(*p).or_insert(0);
            if *lcm_e < *e {
                *lcm_e = *e;
            }
        }
    }

    let mut res = 0;
    let lcm_value = value(&lcm);
    for fac in factors.iter() {
        res = (res + lcm_value * powmod(value(&fac), MO as usize - 2) % MO) % MO;
    }

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

*/

fn main() {
    let exe = "./binXXXXXX";
    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>";