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)

use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

pub fn read_n<T: FromStr>(n: usize) -> Vec<T> {
    read_n_logic::<T>(n, vec![])
}

pub fn read_n_logic<T: FromStr>(n: usize, mut a: Vec<T>) -> Vec<T> {
    match n {
        0 => a,
        _ => {
            a.push(read::<T>());
            read_n_logic(n - 1, a)
        }
    }
}

use std::cmp::{max, min};

const MOD: u64 = 1_000_000_007;

fn prime_factors(a: i64) -> Vec<i64> {
    let mut p: Vec<i64> = vec![];
    let mut num = a;
    let mut d = 2;

    while num > 1 && d <= (a as f64).sqrt() as i64 {
        match num % d {
            0 => {
                p.push(d);
                num = num / d;
            }
            _ => d += 1,
        }
    }

    if num > 1 {
        p.push(num);
    }
    p
}

fn powmod(base: u64, exp: u64, m: u64) -> u64 {
    let b: Vec<bool> = format!("{:b}", exp)
        .chars()
        .map(|x| x.to_digit(10).unwrap() != 0)
        .collect();
    let mut v = 1;
    for bi in b {
        v *= v;
        v %= m;
        if bi {
            v *= base;
            v %= m
        }
    }
    return v % m;
}

fn invmod(x: u64, m: u64) -> u64 {
    powmod(x, m - 2, m)
}

fn main() {
    let max_val = 1_000_000;
    let n: usize = read();
    let a: Vec<i64> = read_n(n);
    let mut primes = vec![0; max_val];

    let mut ans = 0;
    for i in 0..a.len() {
        let ai = a[i];
        let mut prev = 0;
        let mut cnt = 0;
        for i in prime_factors(ai) {
            if i == prev {
                cnt += 1;
            } else {
                primes[prev as usize] = max(primes[prev as usize], cnt);
                prev = i;
                cnt = 1;
            }
        }
        primes[prev as usize] = max(primes[prev as usize], cnt);
    }
    let mut val = 1;

    for i in 0..primes.len() {
        let pi = primes[i];
        if pi != 0 {
            val *= powmod(i as u64, pi, MOD as u64);
            val %= MOD;
        }
    }

    let mut ans = 0;

    for i in 0..a.len() {
        let ai = a[i];
        ans += val * (invmod(ai as u64, MOD as u64) % MOD as u64);
        ans %= MOD as u64;
    }

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