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 Go (1.6) (judge verdict: Wrong Answer)

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

// input scanner
var sc = bufio.NewScanner(os.Stdin)

const (
	initialBufSize = 10e4
	maxBufSize     = 10e6
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextInt64() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

func nextInt64s(n int) []int64 {
	ret := make([]int64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt64()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

// util
func max(l []int) (int, int) {
	idx := 0
	ans := l[idx]
	for i, n := range l {
		if n > ans {
			idx = i
			ans = n
		}
	}
	return idx, ans
}

func min(l []int) (int, int) {
	idx := 0
	ans := l[idx]
	for i, n := range l {
		if n < ans {
			idx = i
			ans = n
		}
	}
	return idx, ans
}

var mod = 1000000007

func mul(a int, b int) int {
	return ((a % mod) * (b % mod)) % mod
}

func power(x int, y int) int {
	if y == 0 {
		return 1
	} else if y%2 == 0 {
		ans := power(x, y/2) % mod
		ans = mul(ans, ans)
		return ans
	} else {
		ans := power(x, y/2) % mod
		ans = mul(mul(ans, ans), x)
		return ans
	}
}

// main
func main() {
	buf := make([]byte, initialBufSize)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)
	n := nextInt()
	a := nextInts(n)
	var ans int
	m := map[int]int{}
	miList := make([]map[int]int, n)
	for i := 0; i < n; i++ {
		mi := map[int]int{}
		res := a[i]
		for j := 2; j <= int(math.Sqrt(float64(a[i]))); j++ {
			if res%j == 0 {
				c := 0
				for res%j == 0 {
					c++
					mi[j]++
					res = res / j
				}
				if c > m[j] {
					m[j] = c
				}
			}
		}
		if res == a[i] {
			mi[res] = 1
			_, exist := m[res]
			if !exist {
				m[res] = 1
			}
		}
		miList[i] = mi
	}
	// fmt.Println("m", m)
	for i := 0; i < n; i++ {
		b := 1
		mi := miList[i]
		// fmt.Println("mi", mi)
		for x, c := range m {
			b = mul(b, power(x, (c-mi[x])))
		}
		ans = (ans + b) % mod
	}
	fmt.Println(ans)
}