15,851,243 members
1.00/5 (2 votes)
See more:
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 23-Jan-22 0:42am

## Solution 1

Having split the string, you need to convert the two numbers to integers:
Python
```c = int(b[0])
d = int(b[1])
```

Comments
CPallini 23-Jan-22 5:42am
5.

## Solution 2

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)```

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)

Top Experts
Last 24hrsThis month
 Richard Deeming 100 OriginalGriff 80 Pete O'Hanlon 70 Richard MacCutchan 45 merano99 40
 OriginalGriff 175 Richard MacCutchan 140 Richard Deeming 140 Pete O'Hanlon 140 k5054 70

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