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 Fortran (gfortran v4.8.4) (judge verdict: Wrong Answer)

module mod_generate_fn
    private
type term
    integer(4):: factor,multiplier
end type
type factorized_num
    type(term), pointer:: num(:)
end type

public factorized_num, generate_fn, init_fn, calc_ldb, div_fn, multipl_fn
contains
subroutine generate_fn(x, fx)
    integer(4):: x, now_x
    type(factorized_num):: fx
    integer(4):: i

    now_x = x
    do i=2, nint(sqrt(real(x)))
        do while (mod(now_x, i) == 0)
            call add_factor_to_fn(fx, i)
            now_x = now_x / i
        end do
    end do

    if (now_x /= 1)then
        call add_factor_to_fn(fx, now_x)
    end if
    ! call print_fn(fx, 'pm')
end subroutine


subroutine init_fn(fx)
    type(factorized_num):: fx
    allocate(fx%num(0))
end subroutine


subroutine add_factor_to_fn(fx,pn)
    type(factorized_num):: fx, tmp
    integer(4):: now_size
    integer(4):: pn, i

    now_size = size(fx%num(:))
    do i=1, size(fx%num(:))
        if (fx%num(i)%factor == pn) then
            fx%num(i)%multiplier = fx%num(i)%multiplier + 1
            return
        end if
    end do
    ! not found num in fx%num(:)%factor--------------------
    call append_fn(fx, pn, 1)
end subroutine


subroutine print_fn(fn, word)
    type(factorized_num):: fn
    integer:: i
    character(*):: word

    print"(a5' : ----------------')", word
    do i = 1, size(fn%num(:))
        print"(i7' * 'i7)", fn%num(i)%factor, fn%num(i)%multiplier
    end do
end subroutine


subroutine calc_ldb(fldb, fn)
    type(factorized_num):: fldb, fn
    integer(4):: i,j
    integer(4):: fac, mul
    logical:: fac_exist
    
    do i=1,size(fn%num(:))
        fac = fn%num(i)%factor
        mul = fn%num(i)%multiplier
        fac_exist = .false.
        
        do j=1, size(fldb%num(:))
            if (fldb%num(j)%factor == fac)then
                fldb%num(j)%multiplier = max(fldb%num(j)%multiplier,mul)
                fac_exist = .true.
                exit
            end if
        end do

        if (.not. fac_exist) call append_fn(fldb,fac,mul)
        ! call print_fn(fldb,'ldb')
    end do
end subroutine

subroutine div_fn(fx, fy, ret)
    type(factorized_num):: fx,fy,ret
    integer(4):: ix,iy, fy_size,fx_size, i
    call init_fn(ret)
    fx_size = size(fx%num(:))
    fy_size = size(fy%num(:))
    ix = 1
    iy = 1

    do while(ix <= fx_size .and. iy <= fy_size)
        if (fy%num(iy)%factor /= fx%num(ix)%factor) then
            
            block
                integer:: fac, mul
                fac = fx%num(ix)%factor
                mul = fx%num(ix)%multiplier
                call append_fn(ret,fac,mul)
            end block
            ix = ix+1
        else

            block
                integer(4):: fac, mul_x, mul_y
                fac = fx%num(ix)%factor
                mul_x = fx%num(ix)%multiplier
                mul_y = fy%num(iy)%multiplier
                call append_fn(ret, fac, mul_x-mul_y)
            end block
            ix = ix+1
            iy = iy+1
        end if
    end do
    
    do i = ix, fx_size; block
        integer:: fac, mul
        fac = fx%num(i)%factor
        mul = fx%num(i)%multiplier
        call append_fn(ret,fac,mul)
    end block;end do
    ! call print_fn(ret,'b')
    end subroutine

subroutine append_fn(fx, fac, mul)
    type(factorized_num):: fx,tmp
    integer(4):: now_size, fac, mul

    now_size = size(fx%num(:))
    allocate(tmp%num(now_size))
    tmp%num(:) = fx%num(:)
    deallocate(fx%num)
    allocate(fx%num(now_size+1))
    fx%num(:now_size) = tmp%num(:)
    deallocate(tmp%num)
    fx%num(now_size+1)%factor = fac
    fx%num(now_size+1)%multiplier = mul
end subroutine

function multipl_fn(fx) result(x)
    type(factorized_num):: fx
    integer(8):: x
    integer(4):: fx_size, i, fac, mul
    integer(4), parameter:: big = 1000000007

    fx_size = size(fx%num(:))
    x = 1
    do i=1, fx_size
        fac = fx%num(i)%factor
        mul = fx%num(i)%multiplier
        x = x*fac**mul
        if (x >= big) x = mod(x,big)
    end do
end function
end module

program flatten
    use mod_generate_fn
    implicit none
    integer(4):: n, i
    integer(4), allocatable:: a(:)
    integer(4), parameter:: big = 1000000007
    integer(8) :: sumb,b
    type(factorized_num), allocatable:: fa(:)
    type(factorized_num):: fldb, fb

    read*, n
    allocate(a(n), fa(n))
    read*, a(:)

    call init_fn(fldb)
    
    do i = 1,n
        call init_fn(fa(i))
        call generate_fn(a(i), fa(i))
        call calc_ldb(fldb,fa(i))
    end do

    sumb = 0

    do i = 1,n
        call div_fn(fldb,fa(i),fb)
        b = multipl_fn(fb)
        sumb = sumb + b
        if (sumb >= big) sumb = mod(sumb,big)
    end do

    print*, sumb
end program flatten