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: Wrong Answer

Solution code:
def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def lm(a, b):
    if a > b:
        a, b = b, a
    while b % a:
        a, b = b % a, a
    return a


def gm(a, b):
    return a * b // lm(a, b)


def Prim(N):
    P = []
    M = int(N ** 0.5) + 1
    F = [False, False] + [True] * M
    for n in range(2, M):
        if not F[n]:
            continue
        P.append(n)
        for i in range(n, len(F), n):
            F[i] = False
    
    return P
 

def ps(a, P):
    d = {}
    for p in P:
        while a % p == 0:
            d[p] = d.setdefault(p, 0) + 1
            a //= p
        
        if a == 1:
            break
    return d


def main():
    mod = 10 ** 9 + 7
    N = int(input())
    A = read_list()
    P = Prim(max(A))
    DA = [ps(a, P) for a in A]
    
    D = {}
    for d in DA:
        for i, v in d.items():
            D[i] = max(D.setdefault(i, 0), v)

    res = 0
    for d in DA:
        b = 1
        for i, v in D.items():
            b = b * (i ** max(0, v - d.setdefault(i, 0))) % mod

        res = (res + b) % mod

    print(res)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
#a/b = a*(b`)となるb`を求める
def mod_inv(a,mod):
    x = extgcd(a,mod)[0]
    return (mod+x%mod)%mod



n = int(input())
mod = 10**9 + 7
a = list(map(int, input().split()))
from fractions import gcd
#from math import gcd
lcm = 1
for i in range(n):
    temp = gcd(lcm,a[i]) % mod
    lcm = (a[i] * lcm) * mod_inv(temp, mod)
    lcm %= mod
ans = 0
for i in range(n):
    ans += lcm * mod_inv(a[i], mod)
    ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
#a/b = a*(b`)となるb`を求める
def mod_inv(a,mod):
    x = extgcd(a,mod)[0]
    return (mod+x%mod)%mod



n = int(input())
mod = 10**9 + 7
a = list(map(int, input().split()))
from fractions import gcd
#from math import gcd
lcm = 1
gcd_a = a[0]
for i in range(n):
    gcd_a = gcd(gcd_a, a[i])
gcd_a %= mod
for i in range(n):
    lcm *= a[i]
    lcm %= mod
lcm *= mod_inv(gcd_a,mod)
ans = 0
for i in range(n):
    ans += lcm * mod_inv(a[i], mod)
    ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
MOD = 10**9 + 7
MAX_NUM = 10**5
is_prime = [True] * MAX_NUM
is_prime[0] = False
is_prime[1] = False
primes = []
for i in range(MAX_NUM):
    if is_prime[i]:
        primes.append(i)
        for j in range(2*i, MAX_NUM, i):
            is_prime[j] = False

def prime_factorization(x):
    res = {}
    for prime in primes:
        while x % prime == 0:
            if not prime in res:
                res[prime] = 0
            res[prime] += 1
            x //= prime
    return res

def inv(p):
    q = MOD - 2
    res = 1
    while q:
        if q & 1:
            res = (res * p) % MOD
        p = (p * p) % MOD
        q //= 2
    return res

def solve(n, a):
    D = {}
    for i in range(n):
        prime_num_mapping = prime_factorization(a[i])
        for prime, num in prime_num_mapping.items():
            if not prime in D:
                D[prime] = 0
            D[prime] = max(D[prime], num)
    L = 1
    for prime, num in D.items():
        for i in range(num):
            L = (L * prime) % MOD
    res = sum(L * inv(x) for x in a)
    return res % MOD

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

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

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

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

tg = 1
for a in A:
    tg = lcm(tg, a)
ans = 0
for a in A:
    ans += tg // a
print(ans)

Submission status: Wrong Answer

Solution code:
def gcd(a,b): 
    if a == 0: 
        return b 
    return gcd(b % a, a) 
  
def lcm(a,b): 
    return (a*b) // gcd(a,b) 

mod = 1000000007
n = int(input())
arr = input()
a = list(map(int, arr.split(' ')))
lc = a[0]
res = 0
for i in range(n):
    lc = lcm(lc, a[i])
for i in range(n):
    res = res + 1//a[i]
print(res % mod)

Submission status: Wrong Answer

Solution code:
from fractions import Fraction
n=int(input())
a=[int(x) for x in input().split()]
M=[]
for i in range(len(a)):
    y=a[i]
    num,den=a[i],a[i]
    f=Fraction(0,1)
    for j in range(len(a)):
        if i!=j:
            f=(Fraction(num,den)+Fraction(y,a[j]))
            num,den=f.numerator,f.denominator
    M.append(f.numerator)
print(min(M)%(10**9+7))

Submission status: Wrong Answer

Solution code:
from fractions import Fraction
n=int(input())
a=[int(x) for x in input().split()]
y=a[0]
num,den=y,y
f=Fraction(0,1)
for i in range(1,len(a)):
    f=(Fraction(num,den)+Fraction(y,a[i]))
    num,den=f.numerator,f.denominator
print(f.numerator%(10**9+7))

Submission status: Wrong Answer

Solution code:
from fractions import gcd


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



MOD = 10 ** 9 + 7

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


_lcm = 1
for a in A:
    # _lcm = lcm(_lcm, a)
    _lcm = _lcm * a / gcd(_lcm, a)
    
ans = _lcm * sum([pow(s, MOD - 2, MOD) for s in A]) % MOD

print(int(ans % MOD))

Submission status: Wrong Answer

Solution code:
from fractions import gcd


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



MOD = 10 ** 9 + 7

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


_lcm = 1
for a in A:
    _lcm = lcm(_lcm, a)

ans = _lcm * sum([pow(s, MOD - 2, MOD) for s in A]) % MOD

print(int(ans % MOD))

Submission status: Wrong Answer

Solution code:
from fractions import gcd


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


MOD = 10**9+7
N = int(input())
A = list(map(int, input().split()))

B = sorted(set(A))

l = 1
for b in B:
    if l % b == 0:
        continue
    l = lcm(l, b)

l %= MOD
ans = 0
for a in A:
    ans += l // a
    ans %= MOD

print(int(ans))

Submission status: Wrong Answer

Solution code:
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))

Submission status: Wrong Answer

Solution code:
#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 in range(2, int(n_input*0.5)+1):
        if not n%i==0:
            continue
        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))

Submission status: Wrong Answer

Solution code:
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))

Submission status: Wrong Answer

Solution code:
def main():
  def sieve(n):
    prime=[]
    limit=n*0.5
    data=[i+1 for i in range(1,n)]
    p_append=prime.append
    while True:
        p=data[0]
        if limit<=p:
            return prime+data
        p_append(p)
        data=[e for e in data if e%p!=0]
        
  prime=sieve(1000)
  import sys
  import numpy as np
  input=sys.stdin.readline
  mod=10**9+7
  
  n=int(input())
  num=list(map(int,input().split()))
  num_copy=np.array(num)
  
  lcm=1
  for p in prime:
    while np.any(num_copy%p==0):
      num_copy[num_copy%p==0]//=p
      lcm *= p
      lcm %= mod
  
  for i in num_copy.tolist():
    lcm*=i
    lcm%=mod
    
  #print(lcm,num)
  ans=0
  for i in range(n):
    ans += lcm * pow(num[i] ,mod-2 ,mod)
    ans %= mod 
    #print(ans)
  print(ans)
  
if  __name__=='__main__':
  main()

Submission status: Wrong Answer

Solution code:
def main():
  def sieve(n):
    prime=[]
    limit=n*0.5
    data=[i+1 for i in range(1,n)]
    while True:
        p=data[0]
        if limit<=p:
            return prime+data
        prime.append(p)
        data=[e for e in data if e%p!=0]
        
  prime=sieve(1000)
  import sys
  import numpy as np
  input=sys.stdin.readline
  mod=10**9+7
  
  n=int(input())
  num=list(map(int,input().split()))
  num_copy=np.array(num)
  
  lcm=1
  for p in prime:
    while np.any(num_copy%p==0):
      num_copy[num_copy%p==0]//=p
      lcm *= p
      lcm %= mod
      
  #print(lcm,num)
  ans=0
  for i in range(n):
    ans += lcm * pow(num[i] ,mod-2 ,mod)
    ans %= mod 
    #print(ans)
  print(ans)
  
if  __name__=='__main__':
  main()

Submission status: Wrong Answer

Solution code:
def main():
  def sieve(n):
    prime=[]
    limit=n*0.5
    data=[i+1 for i in range(1,n)]
    while True:
        p=data[0]
        if limit<=p:
            return prime+data
        prime.append(p)
        data=[e for e in data if e%p!=0]
        
  prime=sieve(1000)
  import sys
  import numpy as np
  input=sys.stdin.readline
  mod=10**9+7
  
  n=int(input())
  num=np.array(list(map(int,input().split())))
  
  lcm=1
  num_copy=num.copy()
  for p in prime:
    while np.any(num%p==0):
      num[num%p==0]//=p
      lcm *= p
      lcm %= mod
      
  #print(lcm,num_copy)
  ans=0
  for i in range(n):
    ans += lcm * pow(num_copy[i] ,mod-2 ,mod)
    ans %= mod 
    #print(ans)
  print(ans)
  
if  __name__=='__main__':
  main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7
from fractions import gcd

l = a[0]
for i in range(n):
  l = l*a[i]//gcd(l,a[i])

b = [0]*n
ans = 0
for i in range(n):
  b[i] = l//a[i]
  ans += b[i]%mod

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
mod = 10*9+7
from fractions import gcd

l = a[0]
for i in range(1,n):
  l = l*a[i]//gcd(l,a[i])

b = [0]*n
ans = 0
for i in range(n):
  b[i] = l//a[i]
  ans += b[i]%mod

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
mod = 10*9+7
from fractions import gcd

l = a[0]
for i in range(n):
  l = l*a[i]//gcd(l,a[i])

b = [0]*n
ans = 0
for i in range(n):
  b[i] = l//a[i]
  ans += b[i]%mod

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.buffer.readline
n = int(input())
a = list(map(int, input().split()))
from fractions import gcd
def lcm(x,y):
  return (x*y)//gcd(x,y)
l = 1
mod = 10**9+7
for i in range(n):
  l = lcm(l, a[i])
l %= mod
ans = 0
for i in range(n):
  ans += l // a[i]
  ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.buffer.readline
n = int(input())
a = list(map(int, input().split()))
from fractions import gcd
def lcm(x,y):
  return (x*y)//gcd(x,y)
l = 1
mod = 10**9+7
for i in range(n):
  l = lcm(l, a[i]) % mod
ans = 0
for i in range(n):
  ans += l // a[i]
  ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
from fractions import gcd
from functools import reduce
import numpy as np
mod = 10**9+7
def lcm(x,y):
  return (x*y)//gcd(x,y)%mod
l = reduce(lcm, a)
print(sum(l//(np.array(a)))%mod)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.buffer.readline
import fractions
from functools import reduce

def main():
    N = int(input())
    a = list(map(int,input().split()))
    MOD = 10**9+7
            
    def lcm(x,y):
        return((x*y)//fractions.gcd(x,y))
        
    l = reduce(lcm,a)
    ans = 0
    for num in a:
        ans += l//num
    
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
Bi = list(map(int, input().split()))
soinsu = []
for i in range(N):
    soinsu.append([])
    B = Bi[i]
    for k in range(int(1+Bi[i]**1/2)):
        while B % (k+2) == 0:
            soinsu[i].append(k+2)
            B = B / (k+2)
soinsu_set = set()
for i in range(N):
    soinsu_set = soinsu_set | set(soinsu[i])
sum_number = 1
for i in soinsu_set:
    count = 0
    for k in range(N):
        count_k = soinsu[k].count(i)
        if count_k > count:
            count = count_k
    sum_number = sum_number * (i ** count)
A = 0
for i in range(N):
    A += sum_number / Bi[i]
print(A%(10**9+7))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = np.array([int(c) for c in input().split()])
MOD = 10**9+7
U = 10**6+10
B = np.zeros(U)
B[2] = 1
B[3::2] = 1
for i in range(3,U):
  if i*i>U:
    break
  if B[i]:
    B[i*i::i+i] = 0
pls = np.where(B[:1000])[0]
inf = [[0]*len(pls) for i in range(N)]
dic = [0]*len(pls)
for i in range(N):
  for j in range(len(pls)):
    p = pls[j]
    ep = 0
    while A[i]%p==0:
      A[i] //= p
      ep += 1
    dic[j] = max(ep, dic[j])
    inf[i][j] = ep
T = set(A)
m = 1
for t in T:
  m *= t
  m %= MOD
ans = 0
for i in range(N):
  b = 1
  for j in (range(len(pls))):
    b *= pls[j]**(dic[j]-inf[i][j])
    b %= MOD
  b *= m
  b %= MOD
  ans += b
  ans %= MOD
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
  from sys import stdin
  from fractions import gcd
  n = int(stdin.readline())
  a = [int(z) for z in stdin.readline().split()]
  lcm = a[0]
  for i in range(1, n):
    lcm = lcm * a[i] // gcd(lcm, a[i])
  sm = 0
  for i in range(n):
    sm += lcm // a[i]
  print(sm)

main()

Submission status: Wrong Answer

Solution code:
import numpy as np
import fractions
from functools import reduce

def main():
    N = int(input())
    A = np.array([int(x) for x in input().split()])
    B = np.zeros(N)
    mod = 10**9+7

    B = lcm(A) // A
    print(sum(B)%mod)

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

def lcm(numlist):
    return reduce(lcm_base, numlist)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import fractions
import numpy as np

# get N
N = int(input())
A = [int(x) for x in input().split()]
#N = 3
#A = [1000000, 999999, 999998]

max_value = 10^9+7

ans = A[0]

for x in range(1, N):
    tmp = fractions.gcd(ans, A[x])
    ans = (ans * A[x]) / tmp

for x in range(len(A)):
    A[x] = ans / A[x]

print(int(sum(A) % max_value))

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))

maximum = max(v)
max_sqrt = int(maximum**0.5)+1
c = [0 for i in range(maximum+1)]

def prim(x):
	v = [0 for i in range(x+1)]
	while x>1:
		for i in range(2, int(x**0.5)+1):
			if x%i == 0:
				v[i] += 1
				x //= i
				break
		else:
			v[x] += 1
			break
	for i, a in enumerate(v):
		c[i] = max(c[i], a)
	return v

all_primes = []
for i in v:
	all_primes.append(prim(i))



total = 0

for i, primes in enumerate(all_primes):

	number = 1
	for j in range(maximum+1):
		if j>1:
			try:
				number *= j**(c[j] - primes[j])
			except IndexError:
				number *= j**(c[j])
	total += number


print(total % (1e9+7))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = np.array(input().split(), np.int64)
MOD = 10**9+7

U = 10**6 + 10
T = np.zeros(U, np.bool)
T[2] = 1
T[3::2] = 1

for p in range(3,U,2):
  if p*p>U:
    break
  if T[p]==1:
    T[p*p::p+p] = 0

pls = np.where(T==1)[0].tolist()
M = pls[:1000]

B = A.copy()
lcm = 1
for p in M:
  e = 0
  while np.any(A%p==0):
    A[A%p==0] //= p
    e += 1
  lcm *= p**e
  lcm %= MOD

x = sum(pow(c, MOD-2, MOD) for c in B.tolist())
print(x*lcm%MOD)

Submission status: Wrong Answer

Solution code:
MOD=10**9+7
class ModInt:
    def __init__(self, x):
        self.x = x % MOD

    def __str__(self):
        return str(self.x)

    __repr__ = __str__

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

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

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

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

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

    __radd__ = __add__

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

    __rmul__ = __mul__

    def __rtruediv__(self, other):
        return (
            ModInt(
                other.x * pow(self.x, MOD - 2, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(other * pow(self.x, MOD - 2, MOD))
        )

    def __rpow__(self, other):
        return (
            ModInt(pow(other.x, self.x, MOD)) if isinstance(other, ModInt) else
            ModInt(pow(other, self.x, MOD))
        )
N=int(input())
A=list(map(int,input().split()))
ans=ModInt(0)
Divisor=dict([(i,0) for i in range(1000000)])
def frac(n,div):
    ret = 0
    while not (n % div) :
        n //= div
        ret += 1
    return ret,n
for i in A:
    divided=i
    for j in range(2,int(divided**(0.5)+1)):
        chk,divided = frac(divided,j)
        if chk > Divisor[j]:Divisor[j] = chk
LCM=ModInt(1)
for i in range(2,1000000):
    LCM*=i**ModInt(Divisor[i])
for i in A:
    ans+=LCM/ModInt(i)
print(ans)

Submission status: Wrong Answer

Solution code:
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    for i in range(N):
        mA = max(0, A[i])
    L = []
    pA = [[] for i in range(N)]
    for i in range(2, int(-(-mA**0.5//1))+1):
        cnt = 0
        for j in range(N):
            if A[j]%i==0:
                tmp = 0
                while A[j]%i==0:
                    tmp+=1
                    A[j]//=i
                pA[j].append([i, tmp])
                cnt = max(cnt, tmp)
        if cnt > 0:
            L.append([i, cnt])
            for j in range(N):
                if len(pA[j]) != len(L):
                    pA[j].append([i, 0])
    for i in range(N):
        if A[i] != 1:
            tmp = A[i]
            for j in range(N):
                if A[j]%tmp==0:
                    A[j]//=tmp
                    pA[j].append([tmp, 1])
                else:
                    pA[j].append([tmp, 0])
            L.append([tmp, 1])
    b = 0
    for i in range(N):
        tmp = 1
        for j in range(len(L)):
            tmp *= L[j][0]**(L[j][1] - pA[i][j][1])
        b += tmp
    print(b % (10**9+7))
resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    for i in range(N):
        mA = max(0, A[i])
    L = []
    pA = [[] for i in range(N)]
    for i in range(2, int(-(-mA**0.5//1))+1):
        cnt = 0
        for j in range(N):
            if A[j]%i==0:
                tmp = 0
                while A[j]%i==0:
                    tmp+=1
                    A[j]//=i
                pA[j].append([i, tmp])
                cnt = max(cnt, tmp)
        if cnt > 0:
            L.append([i, cnt])
            for j in range(N):
                if len(pA[j]) != len(L):
                    pA[j].append([i, 0])
    for i in range(N):
        if A[i] != 1:
            for j in range(N):
                if A[j]%A[i]==0:
                    pA[j].append([A[i], 1])
                else:
                    pA[j].append([A[i], 0])
            L.append([A[i], 1])
            A[i] = 1
    b = 0
    for i in range(N):
        tmp = 1
        for j in range(len(L)):
            tmp *= L[j][0]**(L[j][1] - pA[i][j][1])
        b += tmp
    print(b % (10**9+7))
resolve()

Submission status: Wrong Answer

Solution code:
import fractions
n=int(input())
a=[int(i) for i in input().split()]
g=1
dx=fractions.gcd
for i in a:
  g*=i//dx(g,i)
suml=0
mod=10**9+7
print(g)
for i in a:
  suml+=g*pow(i,mod-2,mod)
  suml%=mod
print(suml)

Submission status: Wrong Answer

Solution code:
import fractions
N = int(input())
a = list(map(int,input().split()))
lcm = a[0]
for i in range(1,N):
	lcm = lcm*a[i]//fractions.gcd(lcm,a[i])

print(lcm)
b = [0]*N

ans = 0
for i in range(N):
	ans += lcm//a[i]
print(int(ans%(10**9+7)))

Submission status: Wrong Answer

Solution code:
from math import sqrt
from fractions import gcd
N = int(input())
A = list(map(int, input().split()))

def insuu(N):
  ret = {}
  for i in range(2,int(sqrt(N)+10)):
    if i > 3 and (i%2 == 0 or i%3 == 0):
      continue
    if N%i == 0:
      ret[i] = 1
      N /= i
    while N%i == 0:
      ret[i] += 1
      N /= i
  if N>1:
    ret[N] = 1
  return ret
   
#for a in A:
#  print(insuu(a))
  
# global lcmを求める
work = insuu(A[0])
for i in range(1,N):
  now = insuu(A[i])
  for k,v in work.items():
    if k in now and now[k] > v:
      work[k] = now[k]
  for k,v in now.items():
    if not k in work:
      work[k] = v
    
#print(work)

# Bを求める
ans = 0
mod = int(1e9+7)

for a in A:
  B = 1
  now = insuu(a)
  for k,v in work.items():
    if k in now:
      x = v - now[k]
    else:
      x = v
    
    for i in range(x):
        B = B * k % mod
    
  ans = (ans + B) % mod
  
print(ans)

Submission status: Wrong Answer

Solution code:
from math import sqrt
from fractions import gcd
N = int(input())
A = list(map(int, input().split()))

def insuu(N):
  ret = {}
  for i in range(2,int(sqrt(N)+10)):
    if i > 3 and (i%2 == 0 or i%3 == 0):
      continue
    if N%i == 0:
      ret[i] = 1
      N /= i
    while N%i == 0:
      ret[i] += 1
      N /= i
  if N>1:
    ret[N] = 1
  return ret
   
#for a in A:
#  print(insuu(a))
  
# global lcmを求める
work = insuu(A[0])
for i in range(1,N):
  now = insuu(A[i])
  for k,v in work.items():
    if k in now and now[k] > v:
      work[k] = now[k]
  for k,v in now.items():
    if not k in work:
      work[k] = v
    
#print(work)

# Bを求める
ans = 0
mod = int(1e9+7)

for a in A:
  B = 1
  now = insuu(a)
  for k,v in work.items():
    if k in now:
      B = B * k ** (v - now[k]) % mod
    else:
      B = B * k ** v % mod
  ans = (ans + B) % mod
  
print(ans)

Submission status: Wrong Answer

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

def lcm(arr):
    ret = arr[0]
    for i in range(1, len(arr)):
        ret = ret * arr[i] / gcd(ret, arr[i])
    return ret

def gcd(a, b):
    if a > b:
        return gcd(b, a)
    while b != 0:
        a, b = b, b % a
    return a

s = 0
m = lcm(A)
for i in range(N):
    s += m / A[i]
print(int(s) % (10**9+7))

Submission status: Wrong Answer

Solution code:
import numpy as np
import fractions

n = int(input())
a = np.array(input().split(),dtype = int)

G = 1

for i in a:
    G = G*i//fractions.gcd(G, i)

ans = 0

for i in a:
    ans += G//i
ans %= 10**9+7

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
a = np.array(input().split(),dtype = int)
ans = 0

pn = [2]
for i in range(3,10**3):
    for j in pn:
        if i%j == 0:
            break
        if j == pn[-1]:
            pn.append(i)
pnum = len(pn)
maxc = [0 for i in range(pnum)]
c = [[0 for i in range(pnum)] for j in range(n)]
overp = [1 for i in range(n)]

for i in range(n):
    pinow = 0
    while not a[i] == 1:
        if a[i]%pn[pinow] == 0:
             c[i][pinow] += 1
             a[i] = int(a[i]/pn[pinow])
             maxc[pinow] = max([maxc[pinow],c[i][pinow]])
        elif pinow == pnum-1:
            overp[i] = a[i]
            a[i] = 1
        else:
            maxc[pinow] = max([maxc[pinow],c[i][pinow]])
            pinow += 1

for i in range(n):
    for j in range(pnum):
        overp[i] = int(overp[i]*(pn[j]**(maxc[j]-c[i][j])))%(10**9+7)
    ans = int(ans+overp[i])%(10**9+7)

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
a = np.array(input().split(),dtype = int)

bsum = 0
lcm_last = 1

def gcd(k,l):
    g = int(k/l)
    if k == g*l:
        return l
    else:
        return gcd(l,k-g*l)

for i in range(n):
    lcm = int(lcm_last*a[i]/gcd(lcm_last,a[i]))
    gcd_time = int(lcm/lcm_last)
    lcm_last = lcm
    bsum = int(bsum*gcd_time+lcm/a[i])%(10**9+7)

print(bsum)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
a = np.array(input().split(),dtype = int)

bsum = 0
lcm_l = 1

def gcd(k,l):
    g = int(k/l)
    if k == g*l:
        return l
    else:
        return gcd(l,k-g*l)

for i in range(n):
    ag = int(lcm_l/gcd(lcm_l,a[i]))
    lcm_l = ag*a[i]
    bsum = (bsum*ag+int(lcm_l/a[i]))%(10**9+7)

print(bsum)

Submission status: Wrong Answer

Solution code:
import fractions

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

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

def solve():
    memo = 0
    for i in range(N - 1):
        if i == 0:
            memo = lcm(A[i], A[i + 1])
        memo = lcm(memo, A[i + 1])

    ans = 0
    for i in range(N):
        ans += memo // A[i]

    return ans % (10 ** 9 + 7)

print(solve())

Submission status: Wrong Answer

Solution code:
import fractions

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

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

def solve():
    memo = 0
    for i in range(N - 1):
        if i == 0:
            memo = lcm(A[i], A[i + 1])
        memo = lcm(memo, A[i + 1])

    for i in range(N):
        A[i] = memo // A[i]

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

Submission status: Wrong Answer

Solution code:
import fractions

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

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

def solve():
    memo = 0
    for i in range(N - 1):
        if i == 0:
            memo = lcm(A[i], A[i + 1])
        memo = lcm(memo, A[i + 1])

    for i in range(N):
        print(A[i])
        A[i] = memo // A[i]

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

Submission status: Wrong Answer

Solution code:
# import math
# import numpy as np
import fractions

# S = input()
N = int(input())
# H, N = map(int, input().split())
A = list(map(int, input().split()))
# B = [int(input()) for _ in range(N)]
# A = []
# B = []
# for _ in range(N):
#     a, b = list(map(int, input().split()))
#     A.append(a)
#     B.append(b)

# 二次元配列
# [[inf, inf, inf], [inf, inf, inf]]
# dp = [[float('inf')] * (H + 1) for i in range(N + 1)]

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

def solve():
    memo = 0
    for i in range(N - 1):
        if i == 0:
            memo = lcm(A[i], A[i + 1])
        memo = lcm(memo, A[i + 1])

    for i in range(N):
        print(A[i])
        A[i] = memo // A[i]

    return sum(A)

print(solve())

Submission status: Wrong Answer

Solution code:
import fractions

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

mod = 10**9+7

R = 1 # 最小公倍数
# 最小公倍数を求める
for A in A_list:
    R *= A // fractions.gcd(R, A)

# Bの合計を求める
ans = 0
for A in A_list:
    ans = ans + R // A # 計算は小数として出してはダメだから//を使う

ans %= mod+7

print(ans)

Submission status: Wrong Answer

Solution code:
import math

mod=1000000007

count=[0 for i in range(1000005)]
def factorize(x):
	lim= int(math.sqrt(x))
	for i in range(2,lim+1):
		if x%i == 0:
			c=0
			while x%i==0:
				x/=i
				c+=1
			x=int(x)

			if count[i]<c: count[i]=c
	if x>1:	count[x]=1

def minu(ans,x):
	lim= int(math.sqrt(x))
	for i in range(2,lim+1):
		if x%i == 0:
			c=0
			while x%i==0:
				x/=i
				c+=1
			x=int(x)

			ans*= pow(pow(i,c),mod-2,mod)
			ans%=mod

	ans*= pow(pow(x,1),mod-2,mod)
	ans%=mod

	return int(ans)

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

ans=0
for x in l:
	factorize(x)

ans=1
for i in range(1,1000005):
	ans*= pow(i,count[i],mod)
	ans%=mod

lc=ans
res=0
for x in l:
	res+=minu(lc,x)
	res%=mod

print(res)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)

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

p = [0 for _ in range(10**6)]
for i in range(n):
    m = l[i]
    cnt = 0
    while m%2 == 0:
        m = m//2
        cnt += 1
    p[2] = max(p[2], cnt)
    for j in range(3, l[i]+1, 2):
        if m==1:
            break
        cnt = 0
        while m%j == 0:
            m = m//j
            cnt += 1
        p[j] = max(p[j], cnt)

ans = 0
for i in range(n):
    _ans = 1
    m = l[i]
    cnt = 0
    while m%2 == 0:
        m = m//2
        cnt += 1
    _ans *= 2**(p[2]-cnt)
    for j in range(3, l[i]+1, 2):
        if m==1:
            break
        cnt = 0
        while m%j == 0:
            m = m//j
            cnt += 1
        _ans *= j**(p[j]-cnt)
    ans += _ans%(10**9+7)
print(ans%(10**9+7))