Buggy python submission (verdict: Time Limit Exceeded):
import math
mod=10**9+7
N=10**6+1
inv_t=[0]+[1]
for i in range(2,N):
    inv_t+=[inv_t[mod%i]*(mod-int(mod/i))%mod]
n=int(input())
A=list(map(int,input().split()))
l=[0]*10**6
for a in A:
    for i in [2]+list(range(3,int(math.sqrt(a))+1,2)):
        c=0
        while a%i==0:
            c+=1
            a//=i
        l[i]=max(l[i],c)
    if a!=1:
        l[a]=max(l[a],1)
lcm=1
for i in range(10**6):
    if l[i]!=0:
        lcm=(lcm*(i**l[i]))%mod
ans=0
for a in A:
    ans=(ans+lcm*inv_t[a])%mod
print(ans)

Fixed submission:
N=10**6+1
mod=10**9+7

inv_l=[0,1]
for i in range(2,N):
    inv_l+=[inv_l[mod%i]*(mod-int(mod/i))%mod]

prime_list=[]
min_prime=[1]*(N+1)
is_prime=[0,0]+[1]*(N-1)
for i in range(2,N+1):
    if is_prime[i]==1:
        prime_list.append(i)
        j=i
        while j<=N:
            is_prime[j]=0
            if min_prime[j]==1:
                min_prime[j]=i
            j+=i

def lcm(l,mod):
    max_count=[0]*(N+1)
    for a in l:
        a_min_prime=min_prime[a]
        a_count=0
        while a>1:
            if min_prime[a]==a_min_prime:
                a_count+=1
                a//=a_min_prime
            else:
                max_count[a_min_prime]=max(max_count[a_min_prime],a_count)
                a_min_prime=min_prime[a]
                a//=a_min_prime
                a_count=1
            if a==1:
                max_count[a_min_prime]=max(max_count[a_min_prime],a_count)
    ret=1
    for i in range(1,N+1):
        if max_count[i]!=0:
            ret=(ret*i**max_count[i])%mod
    return ret

n=int(input())
A=list(map(int,input().split()))
L=lcm(A,mod)
ans=0
for i in range(n):
    ans=(ans+L*inv_l[A[i]])%mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
mod=10**9 + 7
N=10**6+1
inv_t=[0]+[1]
for i in range(2,N):
    inv_t+=[inv_t[mod%i]*(mod-int(mod/i))%mod]
n=int(input())
A=list(map(int,input().split()))
l=[0]*10**6
for a in A:
    for i in range(2,int(math.sqrt(a))+1):
        c=0
        while a%i==0:
            c+=1
            a//=i
        l[i]=max(l[i],c)
    if a!=1:
        l[a]=max(l[a],1)
lcm=1
for i in range(10**6):
    if l[i]!=0:
        lcm=(lcm*(i**l[i]))%mod
ans=0
for a in A:
    ans=(ans+lcm*inv_t[a])%mod
print(ans)

Fixed submission:
N=10**6+1
mod=10**9+7

inv_l=[0,1]
for i in range(2,N):
    inv_l+=[inv_l[mod%i]*(mod-int(mod/i))%mod]

prime_list=[]
min_prime=[1]*(N+1)
is_prime=[0,0]+[1]*(N-1)
for i in range(2,N+1):
    if is_prime[i]==1:
        prime_list.append(i)
        j=i
        while j<=N:
            is_prime[j]=0
            if min_prime[j]==1:
                min_prime[j]=i
            j+=i

def lcm(l,mod):
    max_count=[0]*(N+1)
    for a in l:
        a_min_prime=min_prime[a]
        a_count=0
        while a>1:
            if min_prime[a]==a_min_prime:
                a_count+=1
                a//=a_min_prime
            else:
                max_count[a_min_prime]=max(max_count[a_min_prime],a_count)
                a_min_prime=min_prime[a]
                a//=a_min_prime
                a_count=1
            if a==1:
                max_count[a_min_prime]=max(max_count[a_min_prime],a_count)
    ret=1
    for i in range(1,N+1):
        if max_count[i]!=0:
            ret=(ret*i**max_count[i])%mod
    return ret

n=int(input())
A=list(map(int,input().split()))
L=lcm(A,mod)
ans=0
for i in range(n):
    ans=(ans+L*inv_l[A[i]])%mod
print(ans)