Given two numbers A and B. The task is to find out their LCM and GCD.
 
Example 1:
Input:
A = 5 , B = 10
Output:
10 5
Explanation:
LCM of 5 and 10 is 10, while
thier GCD is 5.
Example 2:
Input:
A = 14 , B = 8
Output:
56 2
Explanation:
LCM of 14 and 8 is 56, while
thier GCD is 2.
 
Your Task:
You don't need to read input or print anything. Your task is to complete the function lcmAndGcd() which takes an Integer N as input and returns a List of two Integers, the required LCM and GCD.
 
Expected Time Complexity: O(log(min(A, B))
Expected Auxiliary Space: O(1)
 
Constraints:
1 <= A,B <= 10^{18}

Difficulty: EASY
Tags: Mathematics
Expected Time Complexity: O(log(min(A, B))
Expected Auxiliary Space: O(1)

Starter code:
#User function Template for python3



class Solution:

    def lcmAndGcd(self, A , B):

        # code here 

Solutions:
class Solution:

	def lcmAndGcd(self, A, B):

		def gcd(a, b):
			while b != 0:
				(a, b) = (b, a % b)
			return a
		lcm = A * B // gcd(A, B)
		return (lcm, gcd(A, B))


import math

class Solution:

	def lcmAndGcd(self, A, B):
		return (int(A * B / math.gcd(A, B)), math.gcd(A, B))


class Solution:

	def lcmAndGcd(self, A, B):
		dupA = A
		dupB = B
		while A != 0 and B != 0:
			if A > B:
				A = A % B
			else:
				B = B % A
		if A == 0:
			return (dupA * dupB // B, B)
		return (dupA * dupB // A, A)


import math

class Solution:

	def lcmAndGcd(self, A, B):
		x = math.gcd(A, B)
		y = A * B // x
		return (y, x)


class Solution:

	def lcmAndGcd(self, A, B):
		ans = []
		a = A
		b = B
		while b != 0:
			temp = b
			b = a % b
			a = temp
		gcd = a
		lcm = A * B // gcd
		ans.append(lcm)
		ans.append(gcd)
		return ans


class Solution:

	def lcmAndGcd(self, A, B):
		prod = A * B
		while A >= 1 and B >= 1:
			if A == B:
				Gcd = A
				break
			if A > B:
				A = A - B
			else:
				B = B - A
		Lcm = prod // Gcd
		return (Lcm, Gcd)


class Solution:

	def lcmAndGcd(self, A, B):
		gcd = cal_gcd(A, B)
		lcm = int(A * B / gcd)
		return [lcm, gcd]

def cal_gcd(a, b):
	while a > 0 and b > 0:
		if a > b:
			a = a % b
		else:
			b = b % a
	if a == 0:
		return b
	else:
		return a


class Solution:

	def lcmAndGcd(self, A, B):
		num_1 = A
		num_2 = B
		while num_2 != 0:
			temp = num_2
			num_2 = num_1 % num_2
			num_1 = temp
		gcd = num_1
		lcm = A * B // gcd
		return [lcm, gcd]


class Solution:

	def lcmAndGcd(self, A, B):
		g = math.gcd(A, B)
		l = A * B // g
		return (l, g)


class Solution:

	def lcmAndGcd(self, A, B):
		(old_a, old_b) = (A, B)
		while B != 0:
			(A, B) = (B, A % B)
		GCD = A
		LCM = abs(old_a * old_b) // GCD
		li = [LCM, GCD]
		return li


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

class Solution:

	def lcmAndGcd(self, A, B):
		if A < B:
			a = A
			b = B
		else:
			a = B
			b = A
		hc = gcd(a, b)
		lc = a / hc
		lc = int(b * lc)
		return (lc, hc)


class Solution:

	def lcmAndGcd(self, A, B):
		a = A
		b = B
		while a != b:
			if a > b:
				a -= b
			else:
				b -= a
		hcf = a
		lcm = A * B // hcf
		dividend = A
		divisor = B
		remainder = dividend % divisor
		while remainder != 0:
			dividend = divisor
			divisor = remainder
			remainder = dividend % divisor
		gcd = divisor
		return (lcm, gcd)


class Solution:

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

	def lcmAndGcd(self, A, B):
		gcm = self.gcd(A, B)
		lcm = A * B // gcm
		return [lcm, gcm]


class Solution:

	def lcmAndGcd(self, A, B):

		def gcd(a, b):
			if b == 0:
				x = a
				return (int(A * B / x), a)
			else:
				return gcd(b, a % b)
		return gcd(A, B)


class Solution:

	def lcmAndGcd(self, A, B):

		def gc(A, B):
			if B == 0:
				return A
			if A < B:
				(A, B) = (B, A)
			temp = A % B
			if temp == B:
				return B
			A = max(temp, B)
			B = min(temp, B)
			return gc(A, B)
		gca = gc(A, B)
		lcm = A * B // gca
		return (lcm, gca)


class Solution:

	def lcmAndGcd(self, A, B):

		def gcd(A, B):
			while B:
				(A, B) = (B, A % B)
			return A
		gc = gcd(A, B)
		lcm = A * B // gc
		return [lcm, gc]


class Solution:

	def lcmAndGcd(self, A, B):
		result = [0] * 2
		(divisor, dividend) = (A, B)
		while divisor != 0:
			remainder = dividend % divisor
			dividend = divisor
			divisor = remainder
		result[1] = dividend
		result[0] = A * B // result[1]
		return result


class Solution:

	def find_gcd(self, a, b):
		if a >= b:
			x = a
			y = b
		else:
			x = b
			y = a
		remainder = y
		while x % y != 0:
			remainder = x % y
			x = y
			y = remainder
		return remainder

	def find_lcm(self, A, B, GCD):
		lcm = A * (B / GCD)
		return lcm

	def lcmAndGcd(self, A, B):
		GCD = self.find_gcd(A, B)
		LCM = self.find_lcm(A, B, GCD)
		return [int(LCM), int(GCD)]


class Solution:

	def lcmAndGcd(self, A, B):
		n = A
		n1 = B
		while B != 0:
			temp = B
			B = A % B
			A = temp
		b = [n * n1 // A, A]
		return b


class Solution:

	def lcmAndGcd(self, a, b):
		a1 = max(a, b)
		b1 = min(a, b)
		q = self.gcd(a1, b1)
		p = a * b // q
		return (p, q)

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


class Solution:

	def lcmAndGcd(self, A, B):
		k1 = A
		k2 = B
		while B:
			(A, B) = (B, A % B)
		l = []
		l.append(k1 * k2 // A)
		l.append(A)
		return l


class Solution:

	def lcmAndGcd(self, a, b):
		a1 = max(a, b)
		b1 = min(a, b)
		c = b1
		rem = a1 % b1
		while rem != 0:
			temp = c
			c = rem
			rem = temp % c
		return (a * b // c, c)


class Solution:

	def lcmAndGcd(self, A, B):
		a = max(A, B)
		b = min(A, B)
		x = b
		r = a % b
		while r != 0:
			t = x
			x = r
			r = t % r
		return (int(A / x * B / x * x), x)


class Solution:

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

	def lcmAndGcd(self, A, B):
		c = self.gcd(A, B)
		lcm = A * B // c
		return (lcm, c)


import math

class Solution:

	def lcmAndGcd(self, A, B):
		gcd = math.gcd(A, B)
		lcm = A * B // gcd
		return (lcm, gcd)


class Solution:

	def lcmAndGcd(self, a, b):
		lcm_a = a
		lcm_b = b
		if a == 0 or b == 0:
			return (0, 0)
		gcd = 1
		while a > 0 and b > 0:
			if a > b:
				a = a % b
			else:
				b = b % a
		if a == 0:
			gcd = b
		else:
			gcd = a
		lcm = lcm_a * lcm_b // gcd
		return (lcm, gcd)


class Solution:

	def lcmAndGcd(self, A, B):
		big = max(A, B)
		small = min(A, B)
		remainder = 0
		while big > 0 and small > 0:
			remainder = big % small
			big = max(small, remainder)
			small = min(small, remainder)
		return [A * B // max(big, small), max(big, small)]


class Solution:

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

	def lcmAndGcd(self, A, B):
		gc = self.gcd(A, B)
		return (int(A * B / gc), gc)


class Solution:

	def calculateGCD(self, a, b):
		if b == 0:
			return a
		else:
			return Solution().calculateGCD(b, a % b)

	def lcmAndGcd(self, A, B):
		if A == 1 and B == 1:
			return [1, 1]
		gcd = Solution().calculateGCD(A, B)
		lcm = int(A * B / gcd)
		return [lcm, gcd]


class Solution:

	def lcmAndGcd(self, A, B):
		(a, b) = (A, B)
		r = a % b
		while r != 0:
			a = b
			b = r
			r = a % b
		GCD = b
		LCM = int(A * B / b)
		return [LCM, GCD]


class Solution:

	def lcmAndGcd(self, A, B):
		n1 = A
		n2 = B
		while n1 > 0 and n2 > 0:
			if n1 > n2:
				n1 = n1 % n2
			else:
				n2 = n2 % n1
		if n1 == 0:
			return (A * B // n2, n2)
		else:
			return (A * B // n1, n1)


class Solution:

	def lcmAndGcd(self, a, b):

		def gcd(a, b):
			if b == 0:
				return a
			return gcd(b, a % b)
		g = gcd(a, b)
		l = a * b // g
		return (l, g)


class Solution:

	def gcd(a, b):
		lesser = min(a, b)
		greater = max(a, b)
		while greater % lesser != 0 and lesser > 0:
			buffer = greater
			greater = lesser
			lesser = buffer % lesser
		return lesser

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

	def lcmAndGcd(self, A, B):
		return (Solution.lcm(A, B), Solution.gcd(A, B))


import math

class Solution:

	def lcmAndGcd(self, A, B):
		result = [0, 0]
		result[1] = math.gcd(A, B)
		result[0] = A * B // result[1]
		return result


class Solution:

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

	def lcmAndGcd(self, A, B):
		gcdAB = self.gcd(A, B)
		return (A * B // gcdAB, gcdAB)


class Solution:

	def gcd(self, A, B):
		if A == 0 or B == 0:
			return max(A, B)
		return self.gcd(max(A, B) % min(A, B), min(A, B))

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


class Solution:

	def lcmAndGcd(self, A, B):
		(A1, B1) = (A, B)
		l1 = []
		while A > 0 and B > 0:
			if A > B:
				A = A % B
			else:
				B = B % A
		if A == 0:
			l1.append(A1 * B1 // B)
			l1.append(B)
		else:
			l1.append(A1 * B1 // A)
			l1.append(A)
		return l1


class Solution:

	def lcmAndGcd(self, A, B):

		def gcd(a, b):
			if b == 0:
				return a
			return gcd(b, a % b)
		g = gcd(A, B)
		return [A * B // g, g]


class Solution:

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

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


class Solution:

	def lcmAndGcd(self, A, B):
		x = A
		y = B
		while y:
			(x, y) = (y, x % y)
		lcm = A * B / x
		return (int(lcm), x)


class Solution:

	def lcmAndGcd(self, A, B):
		hcf = 1
		a = A
		b = B
		while 0 not in [A, B]:
			if A > B:
				A = A % B
				hcf = B
			else:
				B = B % A
				hcf = A
		lcm = a * b // hcf
		return (lcm, hcf)


def gc(x, y):
	if x >= y:
		pass
	else:
		(x, y) = (y, x)
	if x % y == 0:
		return y
	else:
		return gc(y, x % y)

class Solution:

	def lcmAndGcd(self, A, B):
		x = A * B
		gcd = gc(A, B)
		lcm = x // gcd
		l = [lcm, gcd]
		return l


class Solution:

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

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

	def lcmAndGcd(self, A, B):
		gc = self.gcd(A, B)
		lc = self.lcm(A, B, gc)
		return [lc, gc]


class Solution:

	def lcmAndGcd(self, A, B):
		ms = max(A, B)
		mi = min(A, B)
		if ms % mi == 0:
			return [ms, mi]
		else:
			while ms % mi != 0:
				h = ms
				ms = mi
				mi = h % mi
			return [A * B // mi, mi]


class Solution:

	def lcmAndGcd(self, A, B):
		mul = A * B
		gcd = 0
		while A > 0 and B > 0:
			if A > B:
				A = A % B
			else:
				B = B % A
		if A == 0:
			gcd = B
		else:
			gcd = A
		return (mul // gcd, gcd)


import math

class Solution:

	def lcmAndGcd(self, A, B):
		a = A
		b = B
		while b != 0:
			temp = b
			b = a % b
			a = temp
		gcd = a
		lcm = A * B // gcd
		return [lcm, gcd]


class Solution:

	def lcmAndGcd(self, A, B):

		def findgcd(x, y):
			if x == 0:
				return y
			return findgcd(x % y, y) if x > y else findgcd(y % x, x)
		gcd = findgcd(A, B) if A > B else findgcd(B, A)
		lcm = int(A * B / gcd)
		return [lcm, gcd]


class Solution:

	def lcmAndGcd(self, A, B):
		(t1, t2) = (A, B)
		if t1 < t2:
			(t1, t2) = (t2, t1)
		Gcd = self.gcd(t1, t2)
		lcm = A * B // Gcd
		return [lcm, Gcd]

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


class Solution:

	def lcmAndGcd(self, A, B):
		a = A
		b = B
		minn = min(a, b)
		gcd = 1
		while a > 0 and b > 0:
			if a > b:
				a = a % b
			else:
				b = b % a
		if a == 0:
			gcd = b
		else:
			gcd = a
		return [int(A * B / gcd), gcd]


class Solution:

	def gcd(self, a: int, b: int) -> int:
		while b:
			(a, b) = (b, a % b)
		return a

	def lcmAndGcd(self, a: int, b: int) -> tuple:
		gcd = self.gcd(a, b)
		lcm = a * b // gcd
		return (lcm, gcd)


def compute_gcd(a, b):
	while True:
		bigger = max(a, b)
		smaller = min(a, b)
		if a == 0 or b == 0:
			return bigger
		a = bigger - smaller
		b = smaller

class Solution:

	def lcmAndGcd(self, a, b):
		gcd = compute_gcd(a, b)
		return [int(a * b / gcd), gcd]


class Solution:

	def lcmAndGcd(self, A, B):

		def gcd(a, b):
			while a > 0 and b > 0:
				if a > b:
					a = a % b
				else:
					b = b % a
			if a == 0:
				return b
			return a
		if B > A:
			(B, A) = (A, B)
		return [A * B // gcd(A, B), gcd(A, B)]


class Solution:

	def lcmAndGcd(self, A, B):
		HCF = math.gcd(A, B)
		LCM = A * B // HCF
		return (LCM, HCF)