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::HashMap;
use std::collections::VecDeque;
use std::usize::MAX;

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:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn prime_fact(num: u64) -> HashMap<u64, u64> {
    let at_most = (num as f64).sqrt().floor() as u64 + 3;

    let mut primes: HashMap<u64, u64> = HashMap::new();

    let mut tmp_num = num;

    for i in 2..at_most {
        while tmp_num % i == 0 {
            let count = primes.entry(i).or_insert(0);
            *count += 1;
            tmp_num = tmp_num / i;
        }
    }

    primes
}

fn union(origin: &mut HashMap<u64, u64>, fragment: &HashMap<u64, u64>) {
    for (k, v) in fragment.iter() {
        let p = *origin.get(k).unwrap_or(&0);

        if p == 0 {
            origin.insert(*k, *v);
        } else {
            if *v > p {
                origin.insert(*k, *v);
            }
        }
    }
}

fn partition(origin: &HashMap<u64, u64>, fragment: &HashMap<u64, u64>) -> u64 {
    let mut num = 1;
    for (k, v) in origin.iter() {
        let p = *fragment.get(k).unwrap_or(&0);

        num *= power_mod(*k, *v - p, LARGE_PRIME);
    }

    num
}

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

    let mut super_factors: HashMap<u64, u64> = HashMap::new();
    let mut factorized_a: Vec<HashMap<u64, u64>> = vec![HashMap::new(); n];

    for i in 0..n {
        let factors = prime_fact(a[i]);
        union(&mut super_factors, &factors);
        factorized_a[i] = factors;
    }

    let mut ans = 0;
    for i in 0..n {
        ans += partition(&super_factors, &factorized_a[i]);
        ans %= LARGE_PRIME;
    }

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

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet
fn power_mod(base: u64, exp: u64, modulo: u64) -> u64 {
    if exp == 0 {
        return 1;
    } else if exp & 1 == 0 {
        return (power_mod(base, exp / 2, modulo) % modulo).pow(2) % modulo;
    } else {
        return power_mod(base, exp - 1, modulo) % modulo * base % modulo;
    }
}