Given an array A[ ] of N numbers, your task is to find LCM of it modulo 1000000007
Example 1: 
Input:
N = 4
A = {1 , 2 , 8 , 3}
Output:
24
Explanation:
LCM of the given array is 24.
24 % 1000000007 = 24
Example 2: 
Input:
N = 2
A = {1 , 8}
Output:
8
Explanation:
LCM of the given array is 8.
Your Task:
You don't need to read input or print anything. Your task is to complete the function lcmOfArray() which takes an Integer N and an Array A as input and returns the answer.
Expected Time Complexity: O(N*log(N))
Expected Auxiliary Space: O(1)
Constraints:
1 <= N <= 10^{5}
1 <= A[i] <= 10^{5}

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3
class Solution:
	def lcmOfArray(self, N, A):
		# code here

Solutions:
class Solution:

	def lcmOfArray(self, N, arr):

		def lcm(num1, num2):
			if num1 > num2:
				num = num1
				den = num2
			else:
				num = num2
				den = num1
			rem = num % den
			while rem != 0:
				num = den
				den = rem
				rem = num % den
			gcd = den
			lcm = int(int(num1 * num2) / int(gcd))
			return lcm % (10 ** 9 + 7)
		if len(arr) == 0:
			return 0
		if len(arr) == 1:
			return arr[0]
		ans = lcm(arr[0], arr[1])
		for i in range(2, len(arr)):
			ans = lcm(ans, arr[i])
		return ans % (10 ** 9 + 7)


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

def lcm(a, b):
	m = min(a, b)
	n = max(a, b)
	hcf = gcd(m, n)
	lc = int(m / hcf) % 1000000007
	return int(lc * n) % 1000000007

class Solution:

	def lcmOfArray(self, N, A):
		m = 1
		for i in range(len(A) - 1):
			A[i + 1] = lcm(A[i], A[i + 1]) % 1000000007
		return int(A[N - 1] % 1000000007)


class Solution:

	def lcmOfArray(self, N, A):

		def gcd(a, b):
			if b == 0:
				return a
			else:
				return gcd(b, a % b)
		lcm = 1
		for i in A:
			lcm = int(lcm * i / gcd(lcm, i) % 1000000007)
		return lcm


class Solution:

	def lcmOfArray(self, N, A):
		import math
		lcm = A[0]
		for i in range(1, len(A)):
			lcm = int(lcm * A[i] / math.gcd(lcm, A[i]) % 1000000007)
		return lcm


from math import gcd

class Solution:

	def lcmOfArray(self, N, A):
		lcm = 1
		for i in A:
			lcm = lcm * i // gcd(lcm, i) % 1000000007
		return lcm


from functools import reduce
from math import gcd

class Solution:

	def lcmOfArray(self, N, A):
		return reduce(lambda x, y: x * y // gcd(x, y) % 1000000007, A)


class Solution:

	def lcmOfArray(self, N: int, A: list) -> int:

		def gcd(a, b):
			m = max(a, b)
			n = min(a, b)
			if n == 0:
				return m
			else:
				return gcd(n, m % n)

		def lcm(a, b):
			product = a * b
			lcm = product // gcd(a, b)
			return lcm % 1000000007
		lcm_of_array = A[0]
		for i in range(1, N):
			lcm_of_array = lcm(A[i], lcm_of_array)
		return lcm_of_array % 1000000007


class Solution:

	def lcmOfArray(self, N, A):
		m = 1000000007

		def gcd(a, b):
			if a == 0:
				return b
			return gcd(b % a, a)
		ans = A[0]
		for i in A[1:]:
			ans = ans * i // gcd(ans, i) % m
		return ans


from functools import reduce

class Solution:

	def lcmOfArray(self, N, A):
		mod = 10 ** 9 + 7
		gcd = lambda a, b: a if b == 0 else gcd(b, a % b)
		lcd = lambda a, b: int(a * b / gcd(a, b)) % mod
		s = reduce(lcd, A)
		return s % mod


def gcd(A, B):
	a = min(A, B)
	b = max(A, B)
	if a == 0:
		return b
	else:
		r = b % a
		return gcd(a, r)

def lcm(A, B):
	return A * B // gcd(A, B)

class Solution:

	def lcmOfArray(self, N, A):
		ans = 1
		mod = 1000000007
		for i in range(N):
			ans = lcm(ans, A[i]) % mod
		return ans


class Solution:

	def lcmOfArray(self, N, A):
		res = 1
		mod = 1000000007
		for i in range(0, N):
			res = self.lcm(res, A[i]) % mod
		return res

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

	def lcm(self, a, b):
		z = self.gcd(a, b)
		y = a * b
		return y // z


from fractions import gcd
from functools import reduce

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

class Solution:

	def lcmOfArray(self, N, A):
		LCM = reduce(lambda x, y: lcM(x, y) % 1000000007, A)
		return LCM
		lcm = 1
		for i in A:
			lcm = lcm * i // gcd(lcm, i) % 1000000007
		return lcm


class Solution:

	def gcd(self, A, B):
		if A < B:
			return self.gcd(B, A)
		if B == 0:
			return A
		return self.gcd(B, A % B)

	def lcm(self, A, B):
		g = self.gcd(A, B)
		return int(g * (A / g) * (B / g))

	def lcmOfArray(self, N, A):
		l = A[0]
		for i in range(1, N):
			l = self.lcm(l, A[i]) % 1000000007
		return l


from math import *

class Solution:

	def lcmOfArray(self, N, A):
		lcmm = A[0]
		for i in range(0, N):
			b = lcmm
			lcmm = b * A[i] // gcd(lcmm, A[i])
			lcmm = lcmm % 1000000007
		return lcmm


from math import *

class Solution:

	def lcmOfArray(self, N, A):
		a = A[0]
		for i in range(0, N):
			b = a
			a = gcd(a, A[i])
			a = b * A[i] // a
			a = a % 1000000007
		return a
if __name__ == '__main__':
	T = int(input())
	for i in range(T):
		N = int(input())
		A = [int(x) for x in input().split()]
		ob = Solution()
		ans = ob.lcmOfArray(N, A)
		print(ans)


import math

class Solution:

	def lcmOfArray(self, N, A):
		mod = 1000000007
		ans = 1
		for i in A:
			ans = ans * i // math.gcd(ans, i) % mod
		return ans
if __name__ == '__main__':
	T = int(input())
	for i in range(T):
		N = int(input())
		A = [int(x) for x in input().split()]
		ob = Solution()
		ans = ob.lcmOfArray(N, A)
		print(ans)


import math

class Solution:

	def lcmOfArray(self, N, A):
		lcm = 1
		for i in A:
			lcm = lcm * i // math.gcd(lcm, i) % (10 ** 9 + 7)
		return lcm


class Solution:

	def gcd(self, A, B):
		if B == 0:
			return A
		else:
			return self.gcd(B, A % B)

	def lcmOfArray(self, N, A):
		if N > 1:
			currentGCD = self.gcd(A[0], A[1])
		else:
			return A[0]
		lcm = A[0]
		for i in range(1, len(A)):
			lcm = int(lcm * A[i] / self.gcd(lcm, A[i]) % 1000000007)
		return lcm


import math

class Solution:

	def lcmOfArray(self, N, A):
		l = 1
		for i in A:
			l = l * i // math.gcd(l, i) % 1000000007
		return l