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).



Sample input:
3
2 3 4


Sample output:
13

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
def lcm(a):
    from fractions import gcd
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x
A_lcm = lcm(A)
cnt = 0
for i in range(N):
    cnt += A_lcm/A[i]
print(int(cnt%(10**9+7)))

Submission status: Runtime Error

Solution code:
from fractions import gcd

def lcm_pair(a, b):
    return int((a * b) / gcd(a, b))

def lcm(nums):
    if len(nums) > 1:
        l = lcm_pair(nums[0], nums[1])
        return lcm([l] + nums[2:]) if len(nums) > 2 else l
    else:
        return nums[0]

def solve(n, a):
    if n == 1:
        return [1]
    elif n == 2:
        return a
    elif len(set(a)) == 1:
        return [1] * n
    else:
        lcms = [lcm_pair(a[i-1], a[i+1]) for i in range(1, n-1)]
        lcm_max = max(lcms)
        lcm_max_pos = lcms.index(lcm_max) + 1
        b = a.copy()
        b[lcm_max_pos] = lcm(lcms)
        for i in range(lcm_max_pos+1, n):
            b[i] = int((b[i-1] / a[i])) * a[i-1]
        for i in range(lcm_max_pos-1, -1, -1):
            b[i] = int((b[i+1] / a[i])) * a[i+1]
        return b

n = int(input())
a = list(map(int, input().split()))

print(sum(solve(n, a)) % (10 ** 9 + 7))

Submission status: Runtime Error

Solution code:
from fractions import gcd

def lcm_pair(a, b):
    return int((a * b) / gcd(a, b))

def lcm(nums):
    if len(nums) > 1:
        l = lcm_pair(nums[0], nums[1])
        return lcm([l] + nums[2:]) if len(nums) > 2 else l
    else:
        return nums[0]

def solve(n, a):
    lcms = [lcm_pair(a[i-1], a[i+1]) for i in range(1, n-1)]
    lcm_max = max(lcms)
    lcm_max_pos = lcms.index(lcm_max) + 1
    b = a.copy()
    b[lcm_max_pos] = lcm_max
    for i in range(lcm_max_pos+1, n):
        b[i] = int((b[i-1] / a[i])) * a[i-1]
    for i in range(lcm_max_pos-1, -1, -1):
        b[i] = int((b[i+1] / a[i])) * a[i+1]
    return b

n = int(input())
a = list(map(int, input().split()))

print(sum(solve(n, a)) % (10 ** 9 + 7))

Submission status: Runtime Error

Solution code:
import math

def lcm_pair(a, b):
    return int((a * b) / math.gcd(a, b))

def lcm(nums):
    if len(nums) > 1:
        l = lcm_pair(nums[0], nums[1])
        return lcm([l] + nums[2:]) if len(nums) > 2 else l
    else:
        return nums[0]

def solve(n, a):
    lcms = [lcm_pair(a[i-1], a[i+1]) for i in range(1, n-1)]
    lcm_max = max(lcms)
    lcm_max_pos = lcms.index(lcm_max) + 1
    b = a.copy()
    b[lcm_max_pos] = lcm_max
    for i in range(lcm_max_pos+1, n):
        b[i] = int((b[i-1] / a[i])) * a[i-1]
    for i in range(lcm_max_pos-1, -1, -1):
        b[i] = int((b[i+1] / a[i])) * a[i+1]
    return b

n = int(input())
a = list(map(int, input().split()))

print(sum(solve(n, a)) % (10 ** 9 + 7))

Submission status: Runtime Error

Solution code:
import math

n = int(input())
a = list(map(int, input().split()))

def lcm_pair(a, b):
    return int((a * b) / math.gcd(a, b))

def lcm(nums):
    if len(nums) > 1:
        l = lcm_pair(nums[0], nums[1])
        return lcm([l] + nums[2:]) if len(nums) > 2 else l
    else:
        return nums[0]

def solve(n, a):
    lcms = [lcm_pair(a[i-1], a[i+1]) for i in range(1, n-1)]
    lcm_max = max(lcms)
    lcm_max_pos = lcms.index(lcm_max) + 1
    b = a.copy()
    b[lcm_max_pos] = lcm_max
    for i in range(lcm_max_pos+1, n):
        b[i] = int((b[i-1] / a[i])) * a[i-1]
    for i in range(lcm_max_pos-1, -1, -1):
        b[i] = int((b[i+1] / a[i])) * a[i+1]
    return b

print(sum(solve(n, a)) % (10 ** 9 + 7))

Submission status: Runtime Error

Solution code:
import math

n = int(input())
a = list(map(int, input().split()))

def lcm_pair(a, b):
    return int((a * b) / math.gcd(a, b))

def lcm(nums):
    if len(nums) > 1:
        l = lcm_pair(nums[0], nums[1])
        return lcm([l] + nums[2:]) if len(nums) > 2 else l
    else:
        return nums[0]

lcms = [lcm_pair(a[i-1], a[i+1]) for i in range(1, n-1)]
lcmlcm = lcm(lcms)
lcm_max_pos = lcms.index(max(lcms)) + 1
b = lcmlcm

ll = lcmlcm
for i in range(lcm_max_pos+1, n):
    ll = int((ll / a[i])) * a[i-1]
    b += ll

ll = lcmlcm
for i in range(lcm_max_pos, 0, -1):
    ll = int((ll / a[i-1])) * a[i]
    b += ll

print(b % (10 ** 9 + 7))

Submission status: Runtime Error

Solution code:
from math import gcd
M = 10**9+7


def lcm(a, b):
    return (a//gcd(a, b))*b


totalLCM = 1

n = int(input())
a = [int(x) for x in input().split()]
for i in a:
    totalLCM = lcm(totalLCM, i)

ans = 0
for i in a:
    ans += (totalLCM//i)
    ans %= M

print(ans % M)

Submission status: Runtime Error

Solution code:
from math import gcd
M = 10**9+7


def lcm(a, b): return (a//gcd(a, b))*b


totalLCM = 1

n = int(input())
a = [int(x) for x in input().split()]
for i in a:
    totalLCM = lcm(totalLCM, i)

ans = 0
for i in a:
    ans += (totalLCM//i)
    ans %= M

print(ans % M)

Submission status: Runtime Error

Solution code:
import sys
import random
import math
#file = open('test.in', 'r') 
file = sys.stdin
n = (int)(input())
v = list(map(int, input().split()))
lcm = 1
for i in range(n):
	lcm = (v[i] * lcm) // math.gcd(v[i], lcm)
sm = 0
for i in range(n):
	sm = sm + (lcm // v[i])
print(sm % 1000000007)

Submission status: Runtime Error

Solution code:
import sys
import random
import math
#file = open('test.in', 'r') 
file = sys.stdin
n = input()
v = list(map(int, input().split()))
lcm = 1
for i in range(n):
	lcm = (v[i] * lcm) // math.gcd(v[i], lcm)
sm = 0
for i in range(n):
	sm = sm + (lcm // v[i])
print(sm % 1000000007)

Submission status: Runtime Error

Solution code:
N=int(input())
Alist=list(map(int, input().split()))
#N=3
#Alist=[1000000,999999,999998]
import fractions
from functools import reduce
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

import numpy as np
Aarray=np.array(Alist)
Barray=(np.full((1,len(Alist)),lcm_list(Alist))/Aarray)%(10**9+7)
print(int(Barray.sum())%(10**9+7))

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define rep(i,l,r) for(int i=l;i<r;i++)
#define bep(i,l,r) for(int i=l;i>=r;i--)
#define ld long double
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define el '\n'
#define sz(s) s.size()
#define all(v) v.begin(),v.end()
#define mii map<int,int>
#define mr  make_pair
using namespace std;

int inf = 1e18;
const int N = 5e5+5;
int mod = 1e9+7;
int powmod(int a,int b) {int res=1;if(a>=mod)a%=mod;for(;b;b>>=1){if(b&1)res=res*a;if(res>=mod)res%=mod;a=a*a;if(a>=mod)a%=mod;}return res;}

signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
       int n;
       cin>>n;
       unordered_map<int,int> mp;
       int arr[n];
       rep(i,0,n)
       cin>>arr[i];
       rep(i,0,n)
       {
           int ct = 0;
           int x = arr[i];
           for(int i=2;i*i<=x;++i)
           {

               if(x%i==0)
               {
                  ct = 0;
                 while(x%i==0)
                 {
                     ct++;
                     x/=i;
                 }
                 mp[i]= max(mp[i],ct);mp[i]= max(mp[i],ct);
               }

           }
           if(x!=1)
            mp[x] = max(mp[x],1LL);
       }
       int lcm = 1;
       for(auto x:mp)
        lcm = (lcm*powmod(x.ff,x.ss))%mod;
        int ans = 0;
        rep(i,0,n)
       {
           ans = (ans + (lcm*powmod(arr[i],mod-2))%mod)%mod;
       }
        cout<<ans<<el;
    }


        return 0;
    }

Submission status: Runtime Error

Solution code:
N=int(input())
Alist=list(map(int, input().split()))
#N=3
#Alist=[1000000,999999,999998]
import fractions
from functools import reduce
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

import numpy as np
Aarray=np.array(Alist)
Barray=np.full((1,len(Alist)),lcm_list(Alist))/Aarray
print(int(Barray.sum())%(10**9+7))

Submission status: Runtime Error

Solution code:
N=int(input())
Alist=list(map(int, input().split()))
#N=3
#Alist=[1000000,999999,999998]
import fractions
from functools import reduce
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

import numpy as np
Aarray=np.array(Alist)
Barray=np.full((1,len(Alist)),lcm_list(Alist))/Aarray
print(int(Barray.sum()%(10**9+7)))

Submission status: Runtime Error

Solution code:
N=int(input())
Alist=list(map(int, input().split()))
#N=3
#Alist=[1000000,999999,999998]
import math
from functools import reduce
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

import numpy as np
Aarray=np.array(Alist)
Barray=np.full((1,len(Alist)),lcm_list(Alist))/Aarray
print(int(Barray.sum()%(10**9+7)))

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
from math import gcd
b=[]
matrix=1
mod=10**9+7
for i in range(n):
    matrix=matrix*a[i]//gcd(matrix,a[i])
ans=0
for i in range(n):
    b.append(matrix//a[i])
    ans=(ans+b[-1])%mod
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())
As = list(map(int, input().split()))

prime = [2]
for i in range(3, 999, 2):
  for j in range(len(prime)):
    if i % prime[j] == 0:
      break
    elif prime[j] > pow(i, 1/2):
      prime.append(i)
      break
    
mat = np.zeros((n, len(prime)))

for i in range(len(As)):
  a = As[i]
  for j in range(len(prime)):
    while True:
      if a % prime[j] == 0:
        mat[i,j] += 1
        a /= prime[j]
      else:
        break
    if a == 1:
      break

max_exp = mat.max(axis=0)

B_total = 0
for i in range(len(As)):
  _exp = max_exp - mat[i]
  b = 1
  for j in range(len(prime)):
    b *= prime[j]**_exp[j]
  B_total += b
  B_total = B_total % (pow(10,9)+7)

print(int(B_total % (pow(10,9)+7)))

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())
As = list(map(int, input().split()))

prime = [2]
for i in range(3, 999, 2):
  for j in range(len(prime)):
    if i % prime[j] == 0:
      break
    elif prime[j] > pow(i, 1/2):
      prime.append(i)
      break
    
mat = np.zeros((n, len(prime)))

for i in range(len(As)):
  a = As[i]
  for j in range(len(prime)):
    while True:
      if a % prime[j] == 0:
        mat[i,j] += 1
        a /= prime[j]
      else:
        break
    if a == 1:
      break

max_exp = mat.max(axis=0)

B_total = 0
for i in range(len(As)):
  _exp = max_exp - mat[i]
  b = 1
  for j in range(len(prime)):
    b *= prime[j]**_exp[j]
  B_total += b

print(int(B_total % (pow(10,9)+7)))

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())
As = list(map(int, input().split()))

prime = [2]
for i in range(3, 999, 2):
  for j in range(len(prime)):
    if i % prime[j] == 0:
      break
    elif prime[j] > pow(i, 1/2):
      prime.append(i)
      break
    
mat = np.zeros((n, len(prime)))

for i in range(len(As)):
  a = As[i]
  for j in range(len(prime)):
    while True:
      if a % prime[j] == 0:
        mat[i,j] += 1
        a /= prime[j]
      else:
        break
    if a == 1:
      break

LCM = 1
max_exp = mat.max(axis=0)
for j in range(len(prime)):
  LCM *= prime[j]**max_exp[j]

B_total = 0
for i in range(len(As)):
  B_total += LCM / As[i]

print(int(B_total % (pow(10,9)+7)))

Submission status: Runtime Error

Solution code:
def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0

def modinv(a, m):
    g, x, y = xgcd(a, m)
    return x % m

import math
N = int(input())
M = 10 ** 9 + 7
A = list(map(int,input().split()))
ans = 0
lcm = A[0]
for i in range(1,N):
    lcm = (lcm * A[i] // int(math.gcd(lcm,A[i] )) ) % M

for i in range(N):
    ans = (ans + modinv(A[i], M) * lcm) % M 
           
print (ans)

Submission status: Runtime Error

Solution code:
def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0

def modinv(a, m):
    g, x, y = xgcd(a, m)
    return x % m

import math
N = int(input())
M = 10 ** 9 + 7
A = list(map(int,input().split()))
ans = 0
lcm = A[0]
for i in range(1,N):
    lcm = (lcm * A[i] // int(math.gcd(lcm,A[i] )) ) % M

print (lcm)
for i in range(N):
    print((modinv(A[i],M) * lcm) % M)
    ans = (ans + modinv(A[i], M) * lcm) % M 
           
print (ans)

Submission status: Runtime Error

Solution code:
def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0

def modinv(a, m):
    g, x, y = xgcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

import math
N = int(input())
M = 10 ** 9 + 7
A = list(map(int,input().split()))
ans = 0
lcm = A[0]
for i in range(1,N):
    lcm = (lcm * A[i] // int(math.gcd(lcm,A[i] )) ) % M

for i in range(N):
    ans = (ans + modinv(A[i], M) * lcm) % M 
           
print (ans)

Submission status: Runtime Error

Solution code:
from sys import stdin, stdout
from math import gcd
 
ii = lambda: int(stdin.readline())
mi = lambda: map(int, stdin.readline().strip().split())
li = lambda: list(mi())

mod = int(1e9) + 7

N = ii()
A = li()
lcm = A[0]
for i in range(1, len(A)):
	lcm = (lcm // gcd(lcm, A[i])) * A[i]

ans = 0
for i in range(0, len(A)):
	ans = (ans + (lcm // A[i])) % mod

print(ans)

Submission status: Runtime Error

Solution code:
"""
the condition is straightforward.
each element of A and B must multiply to the same value.
to minimise the total of B, simply make that value as small
as possible (since A is fixed).

lcm(2, 3, 4) = 12
therefore B is
12/2, 12/3, 12/4
and the sum of B is
12/2 + 12/3 + 12/4

lcd of a list is loop: lcd(partial, new_value)
lcd(a, b) = ab / gcd(a, b)
"""

from fractions import gcd


def lcm(list_ints):
    lcm_ongoing = 1
    for val in list_ints:
        lcm_ongoing = int(round(val*lcm_ongoing/gcd(val, lcm_ongoing)))
    return lcm_ongoing


def flatten(N, A):
    # get lcm
    lcm_of_A = lcm(A)
    # get sum of lcm/values
    ans = sum(int(round(lcm_of_A/value)) for value in A)
    modulo_value = int(int(10e8)+7)
    return ans % modulo_value


if __name__ == "__main__":
    test1 = \
"""3
2 3 4"""
    test2 = \
"""5
12 12 12 12 12"""
    test3 = \
"""3
1000000 999999 999998"""
    test = test3
    # N = int(test.split("\n")[0])
    # A = list(map(int, test.split("\n")[1].split()))
    N = int(input())
    A = list(map(int, input().split()))
    print(flatten(N, A))

Submission status: Runtime Error

Solution code:
"""
the condition is straightforward.
each element of A and B must multiply to the same value.
to minimise the total of B, simply make that value as small
as possible (since A is fixed).

lcm(2, 3, 4) = 12
therefore B is
12/2, 12/3, 12/4
and the sum of B is
12/2 + 12/3 + 12/4

lcd of a list is loop: lcd(partial, new_value)
lcd(a, b) = ab / gcd(a, b)
"""

from math import gcd


def lcm(list_ints):
    lcm_ongoing = 1
    for val in list_ints:
        lcm_ongoing = int(round(val*lcm_ongoing/gcd(val, lcm_ongoing)))
    return lcm_ongoing


def flatten(N, A):
    # get lcm
    lcm_of_A = lcm(A)
    # get sum of lcm/values
    ans = sum(int(round(lcm_of_A/value)) for value in A)
    modulo_value = int(int(10e8)+7)
    return ans % modulo_value


if __name__ == "__main__":
    test1 = \
"""3
2 3 4"""
    test2 = \
"""5
12 12 12 12 12"""
    test3 = \
"""3
1000000 999999 999998"""
    test = test3
    # N = int(test.split("\n")[0])
    # A = list(map(int, test.split("\n")[1].split()))
    N = int(input())
    A = list(map(int, input().split()))
    print(flatten(N, A))

Submission status: Runtime Error

Solution code:
"""
the condition is straightforward.
each element of A and B must multiply to the same value.
to minimise the total of B, simply make that value as small
as possible (since A is fixed).

lcm(2, 3, 4) = 12
therefore B is
12/2, 12/3, 12/4
and the sum of B is
12/2 + 12/3 + 12/4

lcd of a list is loop: lcd(partial, new_value)
lcd(a, b) = ab / gcd(a, b)
"""

from fractions import gcd


def lcm(list_ints):
    lcm_ongoing = 1
    for val in list_ints:
        lcm_ongoing = int(round(val*lcm_ongoing/gcd(val, lcm_ongoing)))
    return lcm_ongoing


def flatten(N, A):
    # get lcm
    lcm_of_A = lcm(A)
    # get sum of lcm/values
    ans = sum(int(round(lcm_of_A/value)) for value in A)
    modulo_value = int(int(10e9)+7)
    return ans % modulo_value


if __name__ == "__main__":
    test1 = \
"""3
2 3 4"""
    test2 = \
"""5
12 12 12 12 12"""
    test3 = \
"""3
1000000 999999 999998"""
    test = test3
    # N = int(test.split("\n")[0])
    # A = list(map(int, test.split("\n")[1].split()))
    N = int(input())
    A = list(map(int, input().split()))
    print(flatten(N, A))

Submission status: Runtime Error

Solution code:
"""
the condition is straightforward.
each element of A and B must multiply to the same value.
to minimise the total of B, simply make that value as small
as possible (since A is fixed).

lcm(2, 3, 4) = 12
therefore B is
12/2, 12/3, 12/4
and the sum of B is
12/2 + 12/3 + 12/4

lcd of a list is loop: lcd(partial, new_value)
lcd(a, b) = ab / gcd(a, b)
"""

from math import gcd


def lcm(list_ints):
    lcm_ongoing = 1
    for val in list_ints:
        lcm_ongoing = int(round(val*lcm_ongoing/gcd(val, lcm_ongoing)))
    return lcm_ongoing


def flatten(N, A):
    # get lcm
    lcm_of_A = lcm(A)
    # get sum of lcm/values
    ans = sum(int(round(lcm_of_A/value)) for value in A)
    modulo_value = int(int(10e9)+7)
    return ans % modulo_value


if __name__ == "__main__":
    test1 = \
"""3
2 3 4"""
    test2 = \
"""5
12 12 12 12 12"""
    test3 = \
"""3
1000000 999999 999998"""
    test = test3
    # N = int(test.split("\n")[0])
    # A = list(map(int, test.split("\n")[1].split()))
    N = int(input())
    A = list(map(int, input().split()))
    print(flatten(N, A))

Submission status: Runtime Error

Solution code:
def flatten(N, A):
    # get lcm
    lcm_of_A = lcm(A)
    # get sum of lcm/values
    ans = 54
    modulo_value = 10000000007
    return ans % modulo_value
 
 
if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    print(flatten(N, A))

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce


def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

MOD = 1e9+7
N = input()
i = 0
arrs = list(map(int, input().split()))
lcms = lcm_list(arrs)
result = 0
for arr in arrs:
    result = (result+lcms/arr)

print(int(result%MOD))

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce


def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

MOD = 1e9+7
N = input()
i = 0
arrs = list(map(int, input().split()))
lcms = lcm_list(arrs)
result = 0
for arr in arrs:
    result = (result+lcms/arr) % MOD

print(int(result))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce


def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

MOD = 1e9+7
N = input()
i = 0
arrs = list(map(int, input().split()))
lcms = lcm_list(arrs)
result = 0
for arr in arrs:
    result = (result+lcms/arr) % MOD

print(int(result))

Submission status: Runtime Error

Solution code:
from sys import stdin
import math

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

mod = 10 ** 9 + 7
g = 1
ans = 0

for i in range(N):
    d = math.gcd(A[i], g)
    g *= A[i]
    g //= d

for i in range(N):
    ans += (g * pow(A[i], mod - 2, mod)) % mod

print(ans % mod)

Submission status: Runtime Error

Solution code:
def flatten(N, A):
    # get lcm
    lcm_of_A = lcm(A)
    # get sum of lcm/values
    ans = 54
    modulo_value = int(int(10e9)+7)
    return ans % modulo_value


if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    print(flatten(N, A))

Submission status: Runtime Error

Solution code:
"""
the condition is quite simple actually.
each element of A and B must multiply to the same value.
to minimise the total of B, simply make that value as small
as possible (since A is fixed).

lcm(2, 3, 4) = 12
therefore B is
12/2, 12/3, 12/4
and the sum of B is
12/2 + 12/3 + 12/4

lcd of a list is loop: lcd(partial, new_value)
lcd(a, b) = ab / gcd(a, b)
"""

def gcd(x, y):
  return 1


def lcm(list_ints):
    lcm_ongoing = 1
    for val in list_ints:
        lcm_ongoing = int(round(val*lcm_ongoing/gcd(val, lcm_ongoing)))
    return lcm_ongoing


def flatten(N, A):
    # get lcm
    lcm_of_A = lcm(A)
    # get sum of lcm/values
    ans = sum(int(round(lcm_of_A/value)) for value in A)
    modulo_value = int(int(10e9)+7)
    return ans % modulo_value


if __name__ == "__main__":
    test1 = \
"""3
2 3 4"""
    test2 = \
"""5
12 12 12 12 12"""
    test3 = \
"""3
1000000 999999 999998"""
    test = test3
    # N = int(test.split("\n")[0])
    # A = list(map(int, test.split("\n")[1].split()))
    N = int(input())
    A = list(map(int, input().split()))
    print(flatten(N, A))

Submission status: Runtime Error

Solution code:
"""
the condition is straightforward.
each element of A and B must multiply to the same value.
to minimise the total of B, simply make that value as small
as possible (since A is fixed).

lcm(2, 3, 4) = 12
therefore B is
12/2, 12/3, 12/4
and the sum of B is
12/2 + 12/3 + 12/4

lcd of a list is loop: lcd(partial, new_value)
lcd(a, b) = ab / gcd(a, b)
"""

from math import gcd


def lcm(list_ints):
    lcm_ongoing = 1
    for val in list_ints:
        lcm_ongoing = int(round(val*lcm_ongoing/gcd(val, lcm_ongoing)))
    return lcm_ongoing


def flatten(N, A):
    # get lcm
    lcm_of_A = lcm(A)
    # get sum of lcm/values
    ans = sum(int(round(lcm_of_A/value)) for value in A)
    modulo_value = int(int(10e9)+7)
    return ans % modulo_value


if __name__ == "__main__":
    test1 = \
"""3
2 3 4"""
    test2 = \
"""5
12 12 12 12 12"""
    test3 = \
"""3
1000000 999999 999998"""
    test = test3
    # N = int(test.split("\n")[0])
    # A = list(map(int, test.split("\n")[1].split()))
    N = int(input())
    A = list(map(int, input().split()))
    print(flatten(N, A))

Submission status: Runtime Error

Solution code:
"""
the condition is more straightforward than it looks.
each element of A and B must multiply to the same value.
to minimise the total of B, simply make that value as small
as possible (since A is fixed).

lcm(2, 3, 4) = 12
therefore B is
12/2, 12/3, 12/4
and the sum of B is
12/2 + 12/3 + 12/4

lcm of a list is loop: lcm(partial, new_value)
lcm(a, b) = ab / gcd(a, b)
"""

from math import gcd


def lcm(list_ints):
    lcm_ongoing = 1
    for val in list_ints:
        lcm_ongoing = int(round(val*lcm_ongoing/gcd(val, lcm_ongoing)))
    return lcm_ongoing


def flatten(N, A):
    # get lcm
    lcm_of_A = lcm(A)
    # get sum of lcm/values
    ans = sum(int(round(lcm_of_A/value)) for value in A)
    modulo_value = int(int(10e9)+7)
    return ans % modulo_value


if __name__ == "__main__":
    test1 = \
"""3
2 3 4"""
    test2 = \
"""5
12 12 12 12 12"""
    test3 = \
"""3
1000000 999999 999998"""
    test = test3
    # N = int(test.split("\n")[0])
    # A = list(map(int, test.split("\n")[1].split()))
    N = int(input())
    A = list(map(int, input().split()))
    print(flatten(N, A))

Submission status: Runtime Error

Solution code:
"""
the condition is more straightforward than it looks.
each element of A and B must multiply to the same value.
to minimise the total of B, simply make that value as small
as possible (since A is fixed).

lcm(2, 3, 4) = 12
therefore B is
12/2, 12/3, 12/4
and the sum of B is
12/2 + 12/3 + 12/4

lcm of a list is loop: lcm(partial, new_value)
lcm(a, b) = ab / gcd(a, b)
"""

from math import gcd


def lcm(list_ints):
    lcm_ongoing = 1
    for val in list_ints:
        lcm_ongoing = int(round(val*lcm_ongoing/gcd(val, lcm_ongoing)))
    return lcm_ongoing


def flatten(N, A):
    # get lcm
    lcm_of_A = lcm(A)
    # get sum of lcm/values
    ans = sum(int(round(lcm_of_A/value)) for value in A)
    modulo_value = int(int(10e9)+7)
    return ans % modulo_value


if __name__ == "__main__":
    test1 = \
"""3
2 3 4"""
    test2 = \
"""5
12 12 12 12 12"""
    test3 = \
"""3
1000000 999999 999998"""
    test = test3
    # N = int(test.split("\n")[0])
    # A = list(map(int, test.split("\n")[1].split()))
    N = int(intput())
    A = list(map(int, input().split()))
    print(flatten(N, A))

Submission status: Runtime Error

Solution code:
from math import gcd
N = int(input())
lists = list(map(int, input().split()))
g = lists[0]
for i in range(1,N):
    g = g*lists[i] // gcd(g, lists[i])
def div_g(x, g):
    y = g // x
    return y
glist = [g for i in range(0,N)]
lists = list(map(div_g, lists, glist))
ans = sum(lists)
print(ans)

Submission status: Runtime Error

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
#mint
class ModInt:
    def __init__(self, x):
        self.x = x % mod
    
    def __str__(self):
        return str(self.x)
    
    __repr__ = __str__

    def __add__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x + other.x)
        else:
            return ModInt(self.x + other)

    __radd__ = __add__
        
    def __sub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x - other.x)
        else:
            return ModInt(self.x - other)

    def __rsub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(other.x - self.x)
        else:
            return ModInt(other - self.x)

    def __mul__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * other.x)
        else:
            return ModInt(self.x * other)

    __rmul__ = __mul__

    def __truediv__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * pow(other.x, mod-2,mod))
        else:
            return ModInt(self.x * pow(other, mod - 2, mod))
            
    def __rtruediv(self, other):
        if isinstance(other, self):
            return ModInt(other * pow(self.x, mod - 2, mod))
        else:
            return ModInt(other.x * pow(self.x, mod - 2, mod))
            

    def __pow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(self.x, other.x, mod))
        else:
            return ModInt(pow(self.x, other, mod))
            

    def __rpow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(other.x, self.x, mod))
        else:
            return ModInt(pow(other, self.x, mod))


# 素因数分解
def prime_factorization(n):
    fact=[]
    fact=defaultdict(int)
    for i in range(2, int(sqrt(n)) + 1):
        while n % i == 0:
            n //= i
            # fact.append(i)
            fact[i]+=1
            # print(n,i)
    if n!=1:
        fact[n]+=1
    return fact

class Eratosthenes:
    def __init__(self, N:int):
        self.data = [None]*2 + [-1]*(N-1) ##data[i]:=iの素因数が一つ入ってるリスト
        for i in range(2,int(sqrt(N)+1)):
            if self.data[i]!=-1:
                continue
            j = 2*i
            while j<=N:
                self.data[j] = i
                j += i

    def prime_factorization(self,n):
        res = defaultdict(int)
        while self.data[n] != -1:
            prime = self.data[n]
            res[prime] += 1
            n //= prime
        res[n] += 1
        return res

def main():
    N=I()
    A=LI()
    A_max = max(A)
    Eratos = Eratosthenes(A_max)

    lcm = defaultdict(int)
    for a in A:
        p = Eratos.prime_factorization(a)
        for k in p.keys():
            lcm[k] = max(p[k],lcm[k])
    
    L = ModInt(1)
    for l,v in lcm.items():
        L *= l**v
    ans = ModInt(0)
    for a in A:
        ans += L/a
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import math

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

lcm = 1
for a in A:
    lcm *= (a // math.gcd(lcm, a)) % (10**9 + 7)

for i in range(len(A)):
    A[i] = lcm // A[i]

print(sum(A) % (10**9 + 7))

Submission status: Runtime Error

Solution code:
import math

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

lcm = 1
for a in A:
    lcm *= (a // math.gcd(lcm, a)) % (10**9 + 7)

for i in range(len(A)):
    A[i] = int(lcm / A[i])

print(sum(A) % (10**9 + 7))

Submission status: Runtime Error

Solution code:
from math import gcd
N = int(input())
A = list(map(int, input().split()))
 
ans = 0
MOD = 1000000007
 
LCM = A[0]
for i in range(1, N):
    LCM *= A[i] // gcd(LCM, A[i])
    
for a in A:
  ans += LCM // a
  
print(ans%MOD)