# GCD and LCM using Sympy in Python

###### ##########Source code for finding GCD and LCM using Sympy in python#########
```from sympy import *
x = Symbol('x')
expression1, expression2 = x**2 + 4*x - 12, x**2 - 5*x + 6
def findGCD(expression1, expression2):
print("########### Find GCD ############")
factorsExpr1, factorsExpr2 = factor(expression1), factor(expression2)
print("factorsExpr1 : ", factorsExpr1)
print("factorsExpr2 : ", factorsExpr2)
GCD = gcd(expression1, expression2)
print("GCD : ", GCD)
return GCD
def findLCM(expression1, expression2, GCD):
print("########### Find LCM ############")
factorsExpr1, factorsExpr2 = factor(expression1), factor(expression2)
LCM = factor(lcm(expression1, expression2))
print("LCM of Expr1 and Expr2 : ", LCM)
print("f(x)*g(x) = ", factor(expression1*expression2))
print("(f(x)*g(x))/GCD = {0}/{1}".format(factor(expression1*expression2),GCD))
LCM = simplify((factorsExpr1*factorsExpr2)/GCD)
print('Finding LCM using (f(x)*g(x))/GCD" : ', LCM)
return LCM
GCD = findGCD(expression1, expression2)
LCM = findLCM(expression1, expression2, GCD))```
###### ######## OUTPUT #############
```########### Find GCD ############
factorsExpr1 :  (x - 2)*(x + 6)
factorsExpr2 :  (x - 3)*(x - 2)
GCD :  x - 2
########### Find LCM ############
LCM of Expr1 and Expr2 :  (x - 3)*(x - 2)*(x + 6)
f(x)*g(x) =  (x - 3)*(x - 2)**2*(x + 6)
(f(x)*g(x))/GCD = (x - 3)*(x - 2)**2*(x + 6)/x - 2
Finding LCM using (f(x)*g(x))/GCD" :  (x - 3)*(x - 2)*(x + 6)```