Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
I got different output. and I should take input of two numbers in a single variable that's why the taken split() function

eg:-
b = 12 24

What I have tried:

a = int(input())
for i in range(a):
    b = input().split()
    c = b[0]
    d = b[1]
    n1, n2 = c, d
    while c > 0:
        r = c%d 
        d = c
        c = r
gcd = d
lcm = (n1*n2)//gcd
print(gcd)
print(lcm)
Posted
Updated 22-Jan-22 23:42pm

Having split the string, you need to convert the two numbers to integers:
Python
c = int(b[0])
d = int(b[1])
 
Share this answer
 
Comments
CPallini 23-Jan-22 5:42am    
5.
Elaborating Richard's solution...
Python
a = input().split()
n1 = int(a[0])
n2 = int(a[1])
c = n1
d = n2
while c != 0:
  r = c
  c = d % c
  d = r
gcd = d
lcm = (n1*n2)//gcd
print(gcd)
print(lcm)
 
Share this answer
 
Comments
Richard MacCutchan 23-Jan-22 6:33am    
And 5 for a complete answer.
CPallini 23-Jan-22 9:51am    
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900