Given an array arr[] of length N, find the lowest number which has both the maximum and minimum of the array as it's divisor.
 
Example 1:
Input:
N = 4
arr[] = {3, 4, 8, 6}
Output:
24
Explanation:
Minimum of the array is 3, while the
maximum is 8. The lowest number which has
both 3 and 8 as divisors is 24.
Example 2:
Input:
N = 2
arr[] = {1, 8}
Output:
8
Explanation:
Minimum of the array is 1, while the
maximum is 8. The lowest number which has
both 1 and 8 as divisors is 8.
 
Your Task:
You don't need to read input or print anything. Your task is to complete the function getNum() which takes an Integer N and an array arr[] of size N as input and returns the integer.
 
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
 
Constraints:
1 <= N <= 10^{5}
1 <= arr[i] <= 10^{4}

Source: geeksforgeeks | Difficulty: EASY
Tags: Number theory

Starter code: #User function Template for python3



class Solution:

    def getNum(self, arr, N):

        # code here 

Solutions:
class Solution:

	def getNum(self, arr, N):
		a = min(arr)
		b = max(arr)
		maxx = max([a, b])
		while True:
			if maxx % a == 0 and maxx % b == 0:
				return maxx
			maxx += 1


class Solution:

	def getNum(self, arr, N):

		def gcd(a, b):
			if a == 0:
				return b
			return gcd(b % a, a)
		x = max(arr)
		y = min(arr)
		z = x * y // gcd(x, y)
		return z


class Solution:

	def getNum(self, arr, N):
		mx = max(arr)
		mi = min(arr)
		n = 2
		while n < mx * mi:
			if n % mx == 0 and n % mi == 0:
				return n
			n += 1
		return mx * mi


class Solution:

	def getNum(self, arr, N):
		j = 0
		x = min(arr)
		y = max(arr)
		if x == 1 or x == 0:
			for i in range(2, 1000000000):
				if i % y == 0:
					j = i
					break
		else:
			for i in range(2, 1000000000):
				if i % x == 0 and i % y == 0:
					j = i
					break
		return j


class Solution:

	def gcd(self, c, d):
		if d == 0:
			return c
		return self.gcd(d, c % d)

	def getNum(self, arr, N):
		a = min(arr)
		b = max(arr)
		return a * b // self.gcd(a, b)


class Solution:

	def getNum(self, arr, N):
		x = max(arr)
		y = min(arr)
		z = x * y
		while x != 0 and y != 0:
			if x > y:
				x %= y
			else:
				y %= x
		return z // (x + y)


import math

class Solution:

	def getNum(self, arr, N):
		a = min(arr)
		b = max(arr)
		return a // math.gcd(a, b) * b


import math

class Solution:

	def getNum(self, arr, N):
		x = min(arr)
		y = max(arr)
		return x * y // math.gcd(x, y)


import math

class Solution:

	def getNum(self, arr, N):
		n = max(arr)
		m = min(arr)
		k = math.gcd(n, m)
		res = int(n * m / k)
		return res


import math

class Solution:

	def getNum(self, arr, N):
		max1 = max(arr)
		min1 = min(arr)
		gcd = math.gcd(max1, min1)
		lcm = max1 * min1 / gcd
		return int(lcm)


import math

class Solution:

	def getNum(self, arr, N):
		arr.sort()
		x = arr[0]
		y = arr[-1]
		p = math.gcd(x, y)
		v = x * y / p
		return int(v)


from math import gcd

class Solution:

	def getNum(self, arr, N):
		ma = max(arr)
		mi = min(arr)
		return ma * mi // gcd(ma, mi)


from math import *

class Solution:

	def getNum(self, arr, N):
		(m1, m2) = (min(arr), max(arr))
		return m1 * m2 // gcd(m1, m2)