Answer to Question #216330 in Python for sai

Question #216330

LCM and GCD

You are given two integers

x and y. Find the GCD and LCM of the numbers.GCD: Greatest Common Divisor of two integers is the largest positive integer that divides each of the integers.LCM: Least Common Multiple of two integers is the smallest positive multiple of both the integers.Input

The input contains two integers

x and y separated by space.Output

The output contains

GCD and LCM for the given pair of integers.Explanation

Given

x = 6 and y = 14.The GCD of the numbers is

2. The LCM of the numbers is 42.The output is

2 42.


1
Expert's answer
2021-07-12T17:19:38-0400
num1, num2 = input().split(' ')
x = int(num1)
y = int(num2)


def gcd(num1, num2):
    
    i = 1
    while(i <= num1 and i <= num2):
        if(num1 % i == 0 and num2 % i == 0):
            gcd = i
        i = i + 1
    return gcd



lcm = (x*y)//gcd(x,y)
print("The GCD of the numbers is", gcd(x,y))
print("The L.C.M. is",lcm)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS