Problem p02793 (python)

Fixed submission:
from fractions import gcd
#from math import gcd
import numpy as np
import sys
input = sys.stdin.readline
mod = 10**9+7

N = int(input())
A = list(map(int, input().split()))

lcm = 1
for s in A:
    lcm = s*lcm//gcd(lcm, s)

ans = lcm*sum([pow(s, mod-2, mod) for s in A]) % mod
#ans = sum([lcm//s % mod for s in A]) % mod

print(int(ans%mod))

Buggy submission (verdict: Runtime Error):
#from fractions import gcd
from math import gcd
import numpy as np
#import sys
#input = sys.stdin.readline
mod = 10**9+7

N = int(input())
A = list(map(int, input().split()))

lcm=1
for s in A:
    lcm = s*lcm//gcd(lcm, s)

ans = lcm*np.sum([pow(s,mod-2,mod) for s in A])%mod
#ans = sum([lcm//s % mod for s in A]) % mod

print(int(ans))

Buggy submission (verdict: Runtime Error):
#from fractions import gcd
#from math import gcd
import numpy as np
#import math
#import sys
#input = sys.stdin.readline
mod = 10**9+7


def obtain_ps(n):
    ps = {}
    # while(n>1):
    n_input = n

    for i_tmp in range(2, int(n_input**0.5)+1):
        if not n % i_tmp == 0:
            continue
        i_tmp2 = n//i_tmp
        for i in [i_tmp, i_tmp2]:
            i_primary = True
            for j in range(2, int(i**0.5)+1):
                if i % j == 0:
                    i_primary = False
                    break
            if not i_primary:
                continue
            count = 1
            r = i
            while(not n % r):
                count += 1
                r *= i
            count -= 1
            ps[i] = count
            n = n/(i**count)
            if n == 1:
                break
    if n == n_input:
        ps[n] = 1
    return ps


N = int(input())
A = list(map(int, input().split()))

ps = {}
ps_s = []
for s in A:
    ps_tmp = obtain_ps(s)
    ps_s.append(ps_tmp)
    for k, v in ps_tmp.items():
        if k in ps.keys():
            ps[k] = max(v, ps_tmp[k])
        else:
            ps[k] = v

ans = 0
for ps_tmp in ps_s:
    plus = 1
    for k, v in ps.items():
        if k in ps_tmp.keys():
            plus *= k**(v-ps_tmp[k]) % mod
        else:
            plus *= k**v % mod

    ans += plus % mod
#lcm=np.product([k**v for k,v in ps.items()])

#ans = np.sum([lcm // s %mod for s in A]) % mod

print(int(ans % mod))

Buggy submission (verdict: Runtime Error):
#from fractions import gcd
#from math import gcd
import numpy as np
#import math
import sys
input = sys.stdin.readline
mod = 10**9+7


def obtain_ps(n):
    ps = {}
    # while(n>1):
    n_input = n

    for i_tmp in range(2, int(n_input**0.5)+1):
        if not n % i_tmp == 0:
            continue
        i_tmp2 = n//i_tmp
        for i in [i_tmp, i_tmp2]:
            i_primary = True
            for j in range(2, int(i**0.5)+1):
                if i % j == 0:
                    i_primary = False
                    break
            if not i_primary:
                continue
            count = 1
            r = i
            while(not n % r):
                count += 1
                r *= i
            count -= 1
            ps[i] = count
            n = n/(i**count)
            if n == 1:
                break
    if n == n_input:
        ps[n] = 1
    return ps


N = int(input())
A = list(map(int, input().split()))

ps = {}
ps_s = []
for s in A:
    ps_tmp = obtain_ps(s)
    ps_s.append(ps_tmp)
    for k, v in ps_tmp.items():
        if k in ps.keys():
            ps[k] = max(v, ps_tmp[k])
        else:
            ps[k] = v

ans = 0
for ps_tmp in ps_s:
    plus = 1
    for k, v in ps.items():
        if k in ps_tmp.keys():
            plus *= k**(v-ps_tmp[k]) & mod
        else:
            plus *= k**v % mod

    ans += plus % mod
#lcm=np.product([k**v for k,v in ps.items()])

#ans = np.sum([lcm // s %mod for s in A]) % mod

print(int(ans % mod))

Buggy submission (verdict: Runtime Error):
#from fractions import gcd
#from math import gcd
import numpy as np
#import math
#import sys
#input = sys.stdin.readline
mod = 10**9+7

def obtain_ps(n):
    ps={}
    #while(n>1):
    n_input=n

    for i_tmp in range(2, int(n_input**0.5)+1):
        if not n%i_tmp==0:
            continue
        for i in [i_tmp, n//i_tmp]:
            i_primary=True
            for j in range(2, int(i**0.5)+1):
                if i%j==0:
                    i_primary=False
                    break
            if not i_primary:
                continue
            count=1
            r=i
            while(not n%r):
                count +=1
                r*=i
            count-=1
            ps[i]=count
            n=n/(i**count)
            if n==1:
                break
    if n==n_input:
        ps[n]=1
    return ps

N = int(input())
A = list(map(int, input().split()))

ps={}
ps_s=[]
for s in A:
    ps_tmp=obtain_ps(s)
    ps_s.append(ps_tmp)
    for k,v in ps_tmp.items():
        if k in ps.keys():
            ps[k]=max(v, ps_tmp[k])
        else:
            ps[k]=v

ans=0
for ps_tmp in ps_s:
    plus=1
    for k,v in ps.items():
        if k in ps_tmp.keys():
            plus*=k**(v-ps_tmp[k])
        else:
            plus*=k**v

    ans+=plus%mod
#lcm=np.product([k**v for k,v in ps.items()])

#ans = np.sum([lcm // s %mod for s in A]) % mod

print(int(ans%mod))

Buggy submission (verdict: Runtime Error):
#from fractions import gcd
from math import gcd
#import numpy as np
#import sys
#input = sys.stdin.readline
mod = 10**9+7

N = int(input())
A = list(map(int, input().split()))

lcms = [A[0]]
[lcms.append(s*lcms[-1]//gcd(lcms[-1], s) % mod) for s in A]
lcm = lcms[-1]

ans = np.sum([lcm*pow(s, mod-2, mod) % mod for s in A]) % mod

print(int(ans))

Buggy submission (verdict: Runtime Error):
from fractions import gcd
#from math import gcd
#import numpy as np
import sys
input = sys.stdin.readline
mod=10**9+7

N = int(input())
A = list(map(int, input().split()))

lcms=[A[0]]
[lcms.append(s*lcms[-1]//gcd(lcms[-1], s)) for s in A]
lcm=lcms[-1]

ans=np.sum([lcm*pow(s, mod-2, mod) %mod  for s in A]) % mod

print(int(ans))

Buggy submission (verdict: Runtime Error):
from fractions import gcd
#from math import gcd
#import numpy as np

N = int(input())
A = list(map(int, input().split()))

lcms=[A[0]]
[lcms.append(s*lcms[-1]//gcd(lcms[-1], s)) for s in A]

ans=sum([(lcms[-1]//s) %(1e9+7) for s in A])%(10**9+7)

print(int(ans))

Buggy submission (verdict: Runtime Error):
from fractions import gcd
#from math import gcd
#import numpy as np

N = int(input())
A = list(map(int, input().split()))

lcms=[A[0]]
[lcms.append(s*lcms[-1]//gcd(lcms[-1], s)) for s in A]

ans=sum([(lcms[-1]//s) %(1e9+7) for s in A])%(1e9+7)

print(int(ans))

Buggy submission (verdict: Runtime Error):
from fractions import gcd
#from math import gcd
import numpy as np

N = map(int, input().split())
A = list(map(int, input().split()))

lcms=[A[0]]
[lcms.append(s*lcms[-1]//gcd(lcms[-1], s)) for s in A]
ans=np.sum(([lcms[-1]//s for s in A]))%(1e9+7)

print(int(ans))

Buggy submission (verdict: Runtime Error):
#from fractions import gcd
from math import gcd
import numpy as np

N = map(int, input().split())
A = list(map(int, input().split()))

lcms=[A[0]]
[lcms.append(s*lcms[-1]//gcd(lcms[-1], s)) for s in A]
ans=np.sum(([lcms[-1]//s for s in A]))%(1e9+7)

print(int(ans))