Problem:


Least Common Multiple

Find the least common multiple (LCM) of given n integers.

Input

n
a1 a2 ... an

n is given in the first line. Then, n integers are given in the second line.

Output

Print the least common multiple of the given integers in a line.

Constraints

2 ≤ n ≤ 10

1 ≤ ai ≤ 1000

Product of given integers ai(i = 1, 2, ... n) does not exceed 231-1

Sample Input 1

3
3 4 6

Sample Output 1

12

Sample Input 2

4
1 2 3 5

Sample Output 2

30



Sample input:
3
3 4 6


Sample output:
12

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
    if a < b:
        a, b = b, a
    while b:
        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()))

ans = 1
for a in A:
    ans = (ans, a)
print(ans)

Submission status: Wrong Answer

Solution code:
from math import sqrt, floor
from collections import deque
from functools import reduce
from operator import mul


def divide(p):
    global a, lcm, limit

    c, d, f = a.copy(), set(), False
    while True:
        b = set(i for i in c if not (i % p))
        d |= c - b
        b = set(i // p for i in b)
        if not b:
            a = d
            break
        lcm.append(p)
        c = b
        f = True
    if f:
        limit = floor(sqrt(max(c)))


n, a = int(input()), set(map(int, input().split()))
p, lcm, limit = 3, deque(), floor(sqrt(max(a)))

divide(2)

while p <= limit:
    divide(p)
    p += 2

print(reduce(mul, lcm, 1) * reduce(mul, a, 1))

Submission status: Wrong Answer

Solution code:
n = input()
nums = map(int,raw_input().split())
nums = sorted(nums)
x = 2
checklist = [0 for i in xrange(n)]
table = []
while x<=nums[0]:
    i=0
    while i<n:
        if nums[i]%x==0:
            checklist[i]=0
            nums[i] = nums[i]/x
        else:
            checklist[i]=1
        i+=1
    if 0 in checklist:
        table.append(x)
    else:
        x+=1
ans = 1
if len(table)==0:
    for num in nums:
        ans *= num
else:
    for num in nums:
        ans *= num
    for y in table:
        ans *= y
print ans

Submission status: Wrong Answer

Solution code:
n = input()
nums = map(int,raw_input().split())
x = 2
checklist = [0 for i in xrange(n)]
table = []
while x<max(nums)/2:
    i=0
    while i<n:
        if nums[i]%x==0:
            checklist[i]=0
            nums[i] = nums[i]/x
        else:
            checklist[i]=1
        i+=1
    if 0 in checklist:
        table.append(x)
    else:
        x+=1
ans = 1
# print nums
# print table
if len(table)==0:
    for num in nums:
        ans *= num
else:
    for num in nums:
        ans *= num
    for y in table:
        ans *= y
print ans

Submission status: Wrong Answer

Solution code:
n = input()
nums = map(int,raw_input().split())
x = 2
checklist = [0 for i in xrange(n)]
table = []
while x<max(nums):
    i=0
    while i<n:
        if nums[i]%x==0:
            checklist[i]=0
            nums[i] = nums[i]/x
        else:
            checklist[i]=1
        i+=1
    if 0 in checklist:
        table.append(x)
    else:
        x+=1
ans = 1
print nums
print table
if len(table)==0:
    for num in nums:
        ans *= num
else:
    for num in nums:
        ans *= num
    for y in table:
        ans *= y
print ans

Submission status: Wrong Answer

Solution code:
n = input()
nums = map(int,raw_input().split())
x = 2
checklist = [0 for i in xrange(n)]
table = []
while x<max(nums):
    i=0
    while i<n:
        if nums[i]%x==0:
            checklist[i]=0
            nums[i] = nums[i]/x
        else:
            checklist[i]=1
        i+=1
    if 0 in checklist:
        table.append(x)
    else:
        x+=1
ans = 1
# print nums
# print table
if len(table)==0:
    for num in nums:
        ans *= num
else:
    for num in nums:
        ans *= num
    for y in table:
        ans *= y
print ans

Submission status: Wrong Answer

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

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

input()
a=list(map(int,input().split()))
b=1
for i in a:
    b=lcm(b,i)
print(b)

Submission status: Wrong Answer

Solution code:
def GCD(x,y):
    r = x%y
    if r == 0:
        return y
    else:
        return GCD(y,r)


n = int(input())
list1 = list(map(int,input().split()))
result = list1[0]
for i in list1[1:]:
    result = result*i/GCD(i,result)

print(result)

Submission status: Wrong Answer

Solution code:
def gcd(x,y):
    p=min(x,y)
    q=max(x,y)
    while True:
            m=q%p
            if m==0:
#                print(p,q,m,p)
                break
            p=m
            q=p
    g=p
#    if p==q:
#        g=1
#    else:
#        g=p
    return g

c=0
n=int(input())
a=sorted(set(list(map(int, input().split()))))
b=[]
while len(a) > 1:
    n=len(a)
    for i in range(n-1):
        p=a[i]
        q=a[i+1]
        g=gcd(p,q)
        r=a[i]*a[i+1]//g
        b.append(r)
    a=sorted(b)
    b=[]
print(*a)

Submission status: Wrong Answer

Solution code:
def gcd(x,y):
    p=min(x,y)
    q=max(x,y)
    while True:
            m=q%p
            if m==0:
#                print(p,q,m,p)
                break
            p=m
            q=p
#    g=p
    if p==q:
        g=1
    else:
        g=p
    return g

c=0
n=int(input())
a=sorted(set(list(map(int, input().split()))))
b=[]
while len(a) > 1:
    n=len(a)
    for i in range(n-1):
        p=a[i]
        q=a[i+1]
        g=gcd(p,q)

        r=a[i]*a[i+1]//g
        b.append(r)
    a=sorted(b)
    b=[]
print(*a)

Submission status: Wrong Answer

Solution code:
def gcd(x,y):
    p=min(x,y)
    q=max(x,y)
    while True:
            m=q%p
            if m==0:
#                print(p,q,m,p)
                break
            p=m
            q=p
#    g=p
    if p==q:
        g=1
    else:
        g=p
    return g

c=0
n=int(input())
a=sorted(set(list(map(int, input().split()))))
b=[]
while len(a) > 1:
    p=a[0]
    q=a[1]
    g=gcd(p,q)
    a.append(p*q//g)
    a.pop(0)
    a.pop(0)
    a=sorted(a)
print(*a)

Submission status: Wrong Answer

Solution code:
from math import gcd
n=int(input())
num=input().split()
a=num[0]
for i in range(1,n):
    ans=gcd(int(num[i]),int(num[i-1]))
    aa=int(num[i])*int(num[i-1])/ans
print(int(aa))

Submission status: Time Limit Exceeded

Solution code:
input()
a=list(map(int,input().split()))
m=max(a)
i,f=1,0
while i:
    for j in a:
        if (m*i)%j:break
        if j==a[-1]: f=1
    if f:break
    i+=1
print(m*i)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]

def lcm(x, y):
    if x > y:
        big = x
    else:
        big = y

    while(True):
        if((big % x == 0) and (big % y == 0)):
            lcm = big
            break
        big += 1
    return lcm

ans = a[0]
for i in a:
    ans = lcm(ans, i)
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]

def lcm(x, y):
    if x > y:
        big = x
    else:
        big = y

    while(True):
        if((big % x == 0) and (big % y == 0)):
            lcm = big
            break
        big += 1
    return lcm

ans = max(a)
for i in a:
    ans = lcm(ans, i)
    
print(ans)

Submission status: Memory Limit Exceeded

Solution code:
import sys

def multiple_all(x):
    count = 1
    for i in range(0,len(x)):
        count *= x[i]
    return count

def least_common_multiple(x):
    for i in range(min(x),multiple_all(x)):
        j = 0
        while(j < len(x)):
            if(i % x[j] != 0):
                break
            j += 1
        if(j == len(x)):
            return i
    return multiple_all(x)

l = []
for input in sys.stdin:
    l.append(input.split())
l = l[1:]
temp = []
for i in range(0,len(l[0])):
    temp.append(int(l[0][i]))
print least_common_multiple(temp)

Submission status: Accepted

Solution code:
# coding=utf-8


def gcd(n1, n2):
    if n1 < n2:
        n1, n2 = n2, n1

    if n1 == n2 or n2 == 0:
        return n1
    n1, n2 = n2, (n1 % n2)
    return gcd(n1, n2)


def lcm(n1, n2):
    return n1*n2//gcd(n1, n2)


def multi_lcm(numbers_list):
    if len(numbers_list) == 2:
        return lcm(numbers_list[0], numbers_list[1])
    elif len(numbers_list) > 2:
        numbers_list2 = [lcm(numbers_list[0], numbers_list[1])]
        numbers_list2.extend(numbers_list[2:])
        return multi_lcm(numbers_list2)


if __name__ == '__main__':
    n = int(input())
    number_list = list(map(int, input().split()))
    print(multi_lcm(number_list))

Submission status: Accepted

Solution code:
# python template for atcoder1
from functools import reduce
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def gcd(a, b):
    """
    return gcd of a,b
    ユークリッド
    """
    while b:
        a, b = b, a % b
    return a


def list_gcd(l):
    """
    l: list
    l のgcd を返す
    """
    return reduce(gcd, l)


def lcm(a, b):
    """
    a,bの最小公倍数
    """
    return a*b//gcd(a, b)


def list_lcm(l):
    """
    l:list
    lのlcmを返す
    """
    return reduce(lcm, l)


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

Submission status: Accepted

Solution code:
import math,functools as ft
lcm=lambda x,y:x*y//math.gcd(x,y)
print(ft.reduce(lcm,map(int,open(0).read().split()[1:])))

Submission status: Accepted

Solution code:
def gcd(a, b):
    if a < b:
        a, b = b, a
    while b:
        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()))

ans = 1
for a in A:
    ans = lcm(ans, a)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a
    
def lcm(a, b):
    return a * b / gcd(a, b)
    
def lcm_array(arr):
    return reduce(lambda cur, x: lcm(cur, x), arr, arr[0])
    

    
if __name__ == '__main__':
    n = sys.stdin.readline()
    n = int(n)
    arr = sys.stdin.readline()
    arr = map(lambda x: int(x), arr.split())
    
    sys.stdout.write(str(lcm_array(arr)) + '\n')

Submission status: Accepted

Solution code:
import math
def sieve(n):
    p = [1] * (n + 1)
    p[0] = p[1] = 0
    
    for i in range(math.ceil((n + 1) ** 0.5)):
        if p[i]:
            for j in range(2 * i, len(p), i):
                p[j] = 0
    return p

from itertools import compress, count
def prime_factor(n):
    p = sieve(int(n ** 0.5))
    factor = []
    for pi in compress(count(0), p):
        while n % pi == 0:
            n //= pi
            factor.append(pi)

    if n != 1:
        factor.append(n)
    return factor

from collections import Counter
from sys import stdin
readline = stdin.readline

n = int(readline())
c =[Counter(prime_factor(ai)) for ai in map(int, readline().split())]
s = set()
for ci in c:
    s.update(ci.keys())

ret = 1
for i in [i ** max(ci[i] for ci in c) for i in s]:
    ret *= i
print(ret)

Submission status: Accepted

Solution code:
def gcd(m,n):  
    while m % n > 0:
        m, n = n, m % n
    else:
        return n
        
def gen_lcm_list(a):
    '''return a shorter list'''
    b = []
    for i in range(len(a)-1):
        b.append(a[i]*a[i+1]/gcd(a[i],a[i+1]))
    return b

n = int(raw_input())
a = map(int,raw_input().split())
while len(a) > 1:
    a = gen_lcm_list(a)
print a[0]

Submission status: Accepted

Solution code:
def gcd(a, b):
    if a < b: a, b = b, a
    while b:
        t = a / b
        a -= b * t
        a, b = b, a
    return a
def lcm(a, b):
    return a * b / gcd(a, b)
n = input()
print reduce(lambda a, b:lcm(a, b), map(int, raw_input().split()))

Submission status: Accepted

Solution code:
def gcd(a, b):
    if b == 0: return a
    else: return gcd(b, a % b)
def lcm(a, b):
    return a * b / gcd(a, b)
n = input()
print reduce(lambda a, b:lcm(a, b), map(int, raw_input().split()))

Submission status: Accepted

Solution code:
from math import sqrt, floor
from collections import deque
from functools import reduce
from operator import mul


def divide(p):
    global a, lcm, limit

    c, d, f = a.copy(), set(), False
    while True:
        b = set(i for i in c if not (i % p))
        d |= c - b
        if not b:
            a = d
            break
        lcm.append(p)
        c = set(i // p for i in b)
        f = True
    if f:
        limit = floor(sqrt(max(a)))


n, a = int(input()), set(map(int, input().split()))
p, lcm, limit = 3, deque(), floor(sqrt(max(a)))

divide(2)

while p <= limit:
    divide(p)
    p += 2

print(reduce(mul, lcm, 1) * reduce(mul, a, 1))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import fractions


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


def lcms(ns):
    l = len(ns)
    assert l > 1
    if l == 2:
        return lcm(*ns)
    else:
        a = ns.pop()
        return lcm(a, lcms(ns))


if __name__ == "__main__":
    _ = int(input())
    print(lcms(list(map(int, input().split()))))

Submission status: Accepted

Solution code:
import math

k = input()
a = map(int, raw_input().split())

prime = []
#find prime numbers in 1-sqrt(n)
m = int(math.sqrt(1000))
for i in range(m+1):
    prime.append(True)

prime[0] = False
prime[1] = False

for i in range(2, int(math.sqrt(m))):
    if not prime[i]:
        continue
    else:
        for j in range(i+1, int(math.sqrt(m))):
            if j % i == 0:
                prime[j] = False

lcm = {}

for n in a:
    s = []
    i = 2
    num = n
    while True:
        if i == int(math.sqrt(num))+1:
            s.append(str(n))
            break
        if not prime[i] or n % i != 0:
            i += 1
            continue

        if n % i == 0:
            s.append(str(i))
            n /= i
            if n == 1:
                break
    tmp_dict = {}


    for c in s:
        if not c in tmp_dict.keys():
            tmp_dict[c] = 1
        else:
            tmp_dict[c] += 1
    for key in tmp_dict.iterkeys():
        if not key in lcm.keys():
            lcm[key] = tmp_dict[key]
        elif lcm[key] < tmp_dict[key]:
            lcm[key] = tmp_dict[key]

L = 1
for key in lcm.iterkeys():
    if lcm[key] != 0:
            L *= int(key) ** lcm[key]

print "%d" % L

Submission status: Accepted

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()))
ans = a[0]
for i in range(1,n):
    ans = lcm(ans, a[i])
print(ans)

Submission status: Accepted

Solution code:
import functools

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

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



n = int(input())
ns = map(int, input().split())
print(functools.reduce(lcm, ns))

Submission status: Accepted

Solution code:
n = input()
nums = map(int,raw_input().split())
nums = sorted(nums)
i=n-2
x=1
while True:
    if i<0:
        break
    tmp =nums[n-1]*x 
    if tmp%nums[i]==0:
        i-=1
    else:
        x+=1
        i=n-2
print tmp

Submission status: Accepted

Solution code:
n = input()
nums = map(int,raw_input().split())
x = 2
checklist = [0 for i in xrange(n)]
table = []
while x<=max(nums):
    i=0
    while i<n:
        if nums[i]%x==0:
            checklist[i]=0
            nums[i] = nums[i]/x
        else:
            checklist[i]=1
        i+=1
    if 0 in checklist:
        table.append(x)
    else:
        x+=1
ans = 1
# print nums
# print table
if len(table)==0:
    for num in nums:
        ans *= num
else:
    for num in nums:
        ans *= num
    for y in table:
        ans *= y
print ans

Submission status: Accepted

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

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

n=input()
x=map(int,raw_input().split())
ans=[x[0]]
for i in xrange(n-1):
    g=gcd(ans[i],x[i+1])
    ans.append(lcm(ans[i],x[i+1],g))
print(ans[n-1])

Submission status: Accepted

Solution code:
def gcd(m, n):
    r = m % n
    return gcd(n, r) if r else n
def lcm(m, n):
    return m*n/gcd(m, n)
input()
print reduce(lcm, map(int, raw_input().split()))

Submission status: Accepted

Solution code:
def gcd(a,b):
    if a<b:
        tmp = a
        a = b
        b = tmp
    while(b>0):
        n = a%b
        a = b
        b = n
    return a

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

n = int(input())
s = input().split()
arr = []
for i in range(n):
    arr.append(int(s[i]))
a = arr[0]
for i in range(1,n):
    a = lcm(a, arr[i])
print(a)

Submission status: Accepted

Solution code:
def get_primes(n):
  lst = []
  for x in xrange(2, n+1):
    is_prime = True
    for i in xrange(len(lst)):
      if x % lst[i] == 0:
        is_prime = False
        break
    if is_prime:
      lst.append(x)
  return lst

primes = get_primes(1000)
n = int(raw_input())
a = map(int, raw_input().split())
mul_list = {}
for i in xrange(n):
  ai = a[i]
  for j in xrange(len(primes)):
    counter = 0
    while True:
      if ai % primes[j] == 0:
        ai = ai / primes[j]
        counter += 1
      else:
        break
    if counter > 0:
      if primes[j] in mul_list:
        mul_list[primes[j]] = max(mul_list[primes[j]], counter)
      else:
        mul_list[primes[j]] = counter

ans = 1
for k,v in mul_list.items():
  ans *= k ** v
print ans

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
4
1 2 3 5

output:
30
"""

import sys
from functools import reduce


def gcd(x, y):
    if x < y:
        x, y = y, x

    while y > 0:
        r = x % y
        x = y
        y = r

    return x


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


def solve(_n_list):
    return reduce(lcm, _n_list)


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    cnt = int(_input[0])
    n_list = list(map(int, _input[1].split()))
    print(solve(n_list))

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
4
1 2 3 5

output:
30
"""

import sys
from functools import reduce


def gcd(x, y):
    if x < y:
        x, y = y, x

    while y > 0:
        r = x % y
        x = y
        y = r

    return x


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


def solve(_n_list):
    return reduce(lcm, _n_list)


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    cnt = int(_input[0])
    n_list = tuple(map(int, _input[1].split()))
    print(solve(n_list))

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
4
1 2 3 5

output:
30
"""

import sys
from functools import reduce
from operator import mod


def gcd(x, y):
    if x < y:
        x, y = y, x

    while y > 0:
        r = mod(x, y)
        x = y
        y = r

    return x


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


def solve(_n_list):
    return reduce(lcm, _n_list)


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    cnt = int(_input[0])
    n_list = tuple(map(int, _input[1].split()))
    print(solve(n_list))

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
4
1 2 3 5

output:
30
"""

import sys
import fractions
from functools import reduce


def gcd(x, y):
    if x < y:
        x, y = y, x

    while y > 0:
        r = x % y
        x = y
        y = r

    return x


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


def solve(_n_list):
    return reduce(lcm, _n_list)


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    cnt = int(_input[0])
    n_list = tuple(map(int, _input[1].split()))
    print(solve(n_list))

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
4
1 2 3 5

output:
30
"""

import sys
from functools import reduce


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


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


def solve(_n_list):
    return reduce(lcm, _n_list)


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    cnt = int(_input[0])
    n_list = tuple(map(int, _input[1].split()))
    print(solve(n_list))

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
def gcd(a, b):
    if b == 0: return a
    return gcd(b, a % b)

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

n = int(input())
a = list(map(int,input().split()))
p = lcm(a[0],a[1])
for i in range(n):
    p = lcm(p,a[i])
print(int(p))

Submission status: Accepted

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

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

input()
a=list(map(int,input().split()))
b=1
for i in a:
    b=lcm(b,i)
print(b)

Submission status: Accepted

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

def function(n):
    a = []
    if n < 2:
        return a
    while n%2 ==0:
        a.append(2)
        n = n//2
    i = 3
    while i*i <= n:
        if n%i ==0:
            a.append(i)
            n = n//i
        else:
            i += 2
    if n > 1:
        a.append(n)
    return a

diction = {}
for i in range(n):
    prime_factor = function(number[i])
    for k in prime_factor:
        a = prime_factor.count(k)
        if k not in diction:
            diction[k] = a
        elif diction[k] < a:
            diction[k] = a
ans= 1            
for a in diction:
    ans *= a**diction[a]
    
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]

def gcd(x, y):
    while(y):
        x, y = y, x%y
    return x

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

ans = 1
for i in a:
    ans = lcm(ans, i)
    
print(ans)

Submission status: Accepted

Solution code:
import sys
from fractions import gcd
from functools import reduce

def solve():
    n = int(input())
    a = [int(i) for i in input().split()]

    ans = reduce(lcm, a, 1)

    print(ans)

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

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
def GCD(x,y):
    r = x%y
    if r == 0:
        return y
    else:
        return GCD(y,r)


n = int(input())
list1 = list(map(int,input().split()))
result = list1[0]
for i in list1[1:]:
    result = result*i/GCD(i,result)

print(int(result))

Submission status: Accepted

Solution code:
def gcd(a, b):
    if a % b == 0:
        return b
    else:
        return gcd(b, a % b)

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

def solve():
    n = input()
    nums = list(map(int, input().split()))
    c_m = lcm(nums[0], nums[1])
    for n in nums[2:]:
        c_m = lcm(c_m, n)
    print(c_m)

solve()

Submission status: Accepted

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

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

def solve():
    n = input()
    nums = list(map(int, input().split()))
    
    ans = 1
    for n in nums:
        ans = lcm(n, ans)
        
    print(ans)

solve()

Submission status: Accepted

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

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

import functools

def solve():
    n = input()
    nums = map(int, input().split())
    print(functools.reduce(lcm, nums))

solve()

Submission status: Accepted

Solution code:
# Aizu Problem NTL_1_C: Least Common Multiple
#
import itertools
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input2.txt", "rt")


def get_factors(n):
    f = 2
    increments = itertools.chain([1,2,2], itertools.cycle([4,2,4,2,4,6,2,6]))
    for incr in increments:
        if f*f > n:
            break
        while n % f == 0:
            yield f
            n //= f
        f += incr
    if n > 1:
        yield n

N = int(input())
max_powers = {}
for n in [int(_) for _ in input().split()]:
    powers = {}
    for f in get_factors(n):
        powers[f] = powers.get(f, 0) + 1
    for p in powers:
        max_powers[p] = max(powers[p], max_powers.get(p, 0))
lcm = 1
for p in max_powers:
    lcm *= p**max_powers[p]

print(lcm)

Submission status: Accepted

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

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

import functools

def solve():
    n = input()
    nums = map(int, input().split())
    print(functools.reduce(lcm, nums))

solve()

Submission status: Accepted

Solution code:
n = int(input())
a = map(int, input().split())
result = a.__next__()

for nb in a:
    na = result
    result *= nb
    while nb > 0:
        na, nb = nb, na%nb
    result //= na

print(result)

Submission status: Accepted

Solution code:
def gcd(x,y):
    p=min(x,y)
    q=max(x,y)
    while p != q:
        if q > p:
            q = q - p
        else:
            p = p - q
    return q

c=0
n=int(input())
a=sorted(set(list(map(int, input().split()))))
b=[]
while len(a) > 1:
    p=a[0]
    q=a[1]
    g=gcd(p,q)
    if g !=0:
        a.append(p*q//g)
    a.pop(0)
    a.pop(0)
    a=sorted(a)
print(*a)

Submission status: Accepted

Solution code:
def gcd(x,y):
    p=min(x,y)
    q=max(x,y)
    while p != q:
        if q > p:
            q = q - p
        else:
            p = p - q
    return q

n=int(input())
a=sorted(set(list(map(int, input().split()))))
while len(a) > 1:
    p=a[0]
    q=a[1]
    g=gcd(p,q)
    a.append(p*q//g)
    a.pop(0)
    a.pop(0)
    a=sorted(a)
print(*a)

Submission status: Accepted

Solution code:
import math
n=int(input())-1
a=list(map(int,input().split()))
for i in[0]*n:
 x,y=a.pop(),a.pop()
 a+=[x*y//math.gcd(x,y)]
print(*a)

Submission status: Accepted

Solution code:
import math
input();b=1
for a in list(map(int,input().split())):b=a*b//math.gcd(a,b)
print(b)

Submission status: Accepted

Solution code:
def gcd(a,b):
    while b:a,b=b,a%b
    return a
 
def lcm(a,b):
    return a//gcd(a,b)*b
 
input()
a=list(map(int,input().split()))
b=1
for i in a:
    b=lcm(b,i)
print(b)

Submission status: Accepted

Solution code:
def gcd(a, b):
    x, y = [a, b] if a > b else [b, a]
    while y:
        x, y = y, x%y
    return x

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

n = int(input())
A = [int(x) for x in input().split(' ')]

tmp = A[0]
for i in range(1, n):
    tmp = lcm(tmp, A[i])

print(tmp)

Submission status: Accepted

Solution code:
def gcd (a,b):
	if a < b:
		a,b = b,a
	return a if b == 0 else gcd(b,a%b)

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

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

print(ans)

Submission status: Accepted

Solution code:
from math import gcd
from functools import reduce
def lcm(a, b):
    return a*b//gcd(a, b)

n = int(input())
a = [int(i) for i in input().split()]
print(reduce(lcm, a))

Submission status: Accepted

Solution code:
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

n = int(raw_input())
a = map(int, raw_input().split())
l = a[0]

for i in range(1,len(a)):
    b = a[i]
    g = gcd(l,b)
    l = l*b/g
print l

Submission status: Accepted

Solution code:
def gcd(a,b):
    while True:
        if a<b:
            a,b=b,a
        amari=a%b
        if amari==0:
            break
        else:
            a,b=b,amari
    return(b)

n=int(input())
c=list(map(int,input().split()))
for i in range(n-1,0,-1):
    c[i-1]=int(c[i]*c[i-1]/gcd(c[i],c[i-1]))
print(c[0])

Submission status: Accepted

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

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

input()
a=list(map(int,input().split()))
b=1
for i in a:
    b=lcm(b,i)
print(b)

Submission status: Accepted

Solution code:
import math
n=int(input())
a=list(map(int,input().split()))
ans=a[0]
for i in range(1,n):
    ans=ans*a[i]//math.gcd(ans,a[i])
print(ans)

Submission status: Accepted

Solution code:
import math
n=int(input())
a=list(map(int,input().split()))
x=a[0]
for i in range(1,n):
    x=x*a[i]//math.gcd(x,a[i])
print(x)

Submission status: Accepted

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)

n = int(input())

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

print(lcm(*a))

Submission status: Accepted

Solution code:
import math
i = int(input())
line = list(map(int,input().split()))
n = line[0]
for l in range(1,i):n = int(n * line[l] / math.gcd(n,line[l]))
print(n)

Submission status: Accepted

Solution code:
import math
input();b = 1
for i in list(map(int,input().split())):
    b = i*b//math.gcd(i,b)
print(b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import gcd
from functools import reduce
def lcm(x, y):
  return x * y // gcd(x, y)
n = int(input())
alst = list(map(int, input().split()))
print(reduce(lcm, alst))

Submission status: Accepted

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

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

input()
a=list(map(int,input().split()))
b=1
for i in a:
    b=lcm(b,i)
print(b)

Submission status: Accepted

Solution code:
import math
from functools import reduce
def lcm(x,y):
    return (x*y)//math.gcd(x,y)
n = int(input())
a = list(map(int,input().split()))
print(reduce(lcm,a))

Submission status: Accepted

Solution code:
import math
n=int(input())
A=list(int(a) for a in input().split())
ans = A[0]

for i in range(1, n) :
    ans = ans * A[i] // math.gcd(ans, A[i])
    
print(ans)

Submission status: Accepted

Solution code:
import fractions
n = int(input())
a = input().split()
l = list(map(int,a))

ans = l[0]
for i in range(1,n):
    ans = ans * l[i] // fractions.gcd(ans,l[i])
print(ans)

Submission status: Accepted

Solution code:
from functools import reduce
from math import gcd
input()
A = list(map(int, input().split()))

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

ans = reduce(lcm, A)
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

from math import gcd
from functools import reduce

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

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

print(reduce(lcm,a))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

def gcd(x, y):
   if x < y:
      x, y = y, x
   if x % y == 0:
      return y
   else:
      return gcd(y, x % y)

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

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

Submission status: Accepted

Solution code:

def gcd(a,b):
    while b:a,b=b,a%b
    return a
 
def lcm(a,b):
    return a//gcd(a,b)*b
 
input()
a=list(map(int,input().split()))
b=1
for i in a:
    b=lcm(b,i)
print(b)

Submission status: Accepted

Solution code:
import math
n = int(input())
x = 1
for y in list(map(int,input().split())):
    x = y*x // math.gcd(y,x)
print(x)

Submission status: Accepted

Solution code:
import fractions
n=int(input())
x=list(map(int, input().split()))   
y=x[0]

for i in range(1,n):
    y = y * x[i] // fractions.gcd(y, x[i])
print(y)

Submission status: Accepted

Solution code:
import math
def LCM(x, y):
    return (x * y) // math.gcd(x, y)
n = int(input())
a = list(map(int,input().split()))
lcm = 1
for ai in a:
  lcm =LCM(ai,lcm)
print(lcm)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
def gcd(a, b) :
    while True :
        if a < b :
            a, b = b, a
        amari = a % b
        if amari == 0 :
            break
        else :
            a, b = b, amari
    return(b)

n = int(input())
c = list(map(int, input().split()))
for i in range(n-1, 0, -1) :
    c[i-1] = int(c[i] * c[i-1] / gcd(c[i], c[i-1]))
print(c[0])