Problem:


GCD and LCM

Write a program which computes the greatest common divisor (GCD) and the least common multiple (LCM) of given a and b. 

Input

Input consists of several data sets. Each data set contains a and b separated by a single space in a line. The input terminates with EOF.

Constraints

 0 < a, b ≤ 2,000,000,000

 LCM(a, b) ≤ 2,000,000,000

 The number of data sets ≤ 50

Output

For each data set, print GCD and LCM separated by a single space in a line.

Sample Input

8 6
50000000 30000000

Output for the Sample Input

2 24
10000000 150000000



Sample input:
8 6
50000000 30000000


Sample output:
2 24
10000000 150000000

Submission status: Time Limit Exceeded

Solution code:
import sys


def gcd(a, b):
    ret = None
    if a == b:
        return a
    elif a < b:
        large = b
    else:
        large = a
    for i in xrange(large, 0, -1):
        if a % i == 0 and b % i == 0:
            ret = i
            break
    return ret


def lcm(a, b):
    ret = None
    lst = [a, b]
    while True:
        if a == b:
            ret = a
            break
        if a > b:
            b += lst[1]
        else:
            a += lst[0]
    return ret


def main():
    for line in sys.stdin.readlines():
        a, b = [int(n) for n in line.split()]
        print "{0} {1}".format(gcd(a, b), lcm(a, b))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys


def gcd(a, b):
    ret = None
    if a > b:
        s = b
    else:
        s = a
    for i in xrange(s, 0, -1):
        if a % i == 0 and b % i == 0:
            ret = i
            break
    return ret


def lcm(a, b):
    ret = None
    lst = [a, b]
    while True:
        if a == b:
            ret = a
            break
        if a > b:
            b += lst[1]
        else:
            a += lst[0]
    return ret


def main():
    for line in sys.stdin.readlines():
        a, b = [int(n) for n in line.split()]
        print "{0} {1}".format(gcd(a, b), lcm(a, b))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:

import sys
def lcm(x, y):
  if x > y:
      greater = x
  else:
      greater = y

  while(True):
      if((greater % x == 0) and (greater % y == 0)):
          lcm = greater
          break
      greater += 1

  return lcm
def gcd(x, y):
  while(y):
      x = y
      y = x%y
  return x
for line in sys.stdin.readlines():
  num1,num2 = map(int,line.split())
  print(lcm(num1,num2),gcd(num1,num2))

Submission status: Time Limit Exceeded

Solution code:
while True:
	ans=""
	try:
		n=input().split()
	except:
		break
	
	a,b=int(n[0]),int(n[1])
	ma,mi=[],[]
	
	for i in range(2,max(a,b)):
		while a%i==0:
			a/=i
			ma.append(i)
			if b%i==0:
				b/=i
				mi.append(i)
		while b%i==0:
			b/=i
			ma.append(i)
	check=1
	for i in mi:
		check*=i
	ans+=str(check)+" "
	check=1
	for i in ma:
		check*=i
	ans+=str(check)
	print(ans)

Submission status: Time Limit Exceeded

Solution code:
while True:
	ans=""
	try:
		n=input().split()
	except:
		break
	if n=="":
		break
	
	
	a,b=int(n[0]),int(n[1])
	ma,mi=[],[]
	count=2
	while a!=1 and b!=1:
		try:
			check_0=max(a,b)
		except:
			break
		for i in range(count,max(a,b)):
			while a%i==0:
				a/=i
				ma.append(i)
				if b%i==0:
					b/=i
					mi.append(i)
				count=i
				break
			while b%i==0:
				b/=i
				ma.append(i)
				count=i
				break
	check=1
	for i in mi:
		check*=i
	ans+=str(check)+" "
	check=1
	for i in ma:
		check*=i
	ans+=str(check)
	print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

temp = []
largest = 1

for line in sys.stdin:
    a,b = [int(x) for x in line.split()]
    if a > b:
        x,y = a,b
    else:
        x,y = b,a
    i = x
    while i > 1:
        if (x % i) == 0 and (y % i) == 0:
            x = x / i
            y = y / i
            largest *= i
        i -= 1
    smallest = largest * (a/largest) * (b/largest)
    print('%d %d' % (largest, smallest))
    largest = 1

Submission status: Time Limit Exceeded

Solution code:
while True:
    try:
        n=input().split()
    except:
        break
    num=[int(n[i]) for i in range(len(n))]
    max=1
    num=sorted(num)
    for i in range(1,num[0]+1):
        if num[0]%i==0:
            if num[1]%i==0:
                max=i
    print(max,int(num[0]*num[1]/max))

Submission status: Time Limit Exceeded

Solution code:
# This program computes GCD and LCM
# -*- coding: utf-8
import sys


def gcd(a, b):
    g = 1
    for i in range(1, max([a, b])):
        if(a % i == 0 and b % i == 0):
            g = i
    return g


def lcm(a, b):
    for i in range(max([a, b]), a*b + 1):
        if(i % a == 0 and i % b == 0):
            return i
    return a*b


for i in sys.stdin:
    try:
        line = [int(k) for k in i.split(" ")]
        print(str(gcd(line[0], line[1])) + " " + str(lcm(line[0], line[1])))
    except:
        exit()

Submission status: Time Limit Exceeded

Solution code:
# This program computes GCD and LCM
# -*- coding: utf-8
import sys


def gcd(a, b):
    for i in range(max([a, b]), 0, -1):
        if(a % i == 0 and b % i == 0):
            return i
    return 1


def lcm(a, b):
    for i in range(max([a, b]), a*b + 1):
        if(i % a == 0 and i % b == 0):
            return i
    return a*b


for i in sys.stdin:
    try:
        line = [int(k) for k in i.split(" ")]
        g = gcd(line[0], line[1])
        print(str(g) + " " + str(line[0]*line[1]//g))  # + str(lcm(line[0], line[1]))
    except:
        exit()

Submission status: Time Limit Exceeded

Solution code:
while True:
        try:
            list = [int(x) for x in raw_input().split(" ")]
            list.sort(lambda x, y: y - x)
            gcd = lcm = 0
            m = list[0]
            n = list[1]
            while True:
                r = m%n
                if r == 0:
                    gcd = n
                    break
                m = n
                n = r
            num = list[0]
            while True:
                if num%list[0] == num%list[1] == 0:
                    lcm = num
                    break
                num += gcd
            print(str(gcd) + " " + str(lcm))
        except EOFError:
            break

Submission status: Time Limit Exceeded

Solution code:
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
import sys

for line in sys.stdin:
    small, large = sorted(int(n) for n in line .split())
    for i in xrange(small, 0, -1):
        if large % i == 0 and small % i == 0:
            gcd = i
            break
    for i in xrange(2, large + 1):
        if i * small % large == 0:
            lcm = i * small
            break
    print(gcd, lcm)

Submission status: Time Limit Exceeded

Solution code:
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
import sys

for line in sys.stdin:
    small, large = sorted(int(n) for n in line .split())
    for i in (n for n in xrange(small, 0, -1) if not small % n):
        if not large % i:
            gcd = i
            break
    for i in xrange(2, small + 1):
        if not i * large % small:
            lcm = i * large
            break
    print(gcd, lcm)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

import sys

outList = []
for line in sys.stdin.readlines():
    List = map(int, line.strip().split())

    [a, b] = List

    factorList = [[0], [1]]
    # LCM
    LCM = 1
    for i in xrange(2, max(a, b)):
        while(a % i == 0 and b % i == 0):
            LCM *= i
            a /= i
            b /= i

    # GCD
    GCD = List[0] * b

    print LCM, GCD

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

import sys

outList = []
for line in sys.stdin.readlines():
    List = map(int, line.strip().split())

    [a, b] = List

    # LCM
    LCM = 1
    for i in xrange(2, max(a, b)):
        while(a % i == 0 and b % i == 0):
            LCM *= i
            a /= i
            b /= i

    # GCD
    GCD = List[0] * b

    print LCM, GCD

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

import sys

def isprime(n):
    for i in xrange(2, int(n ** 0.5)+1 ):
        if n % i == 0: return False
    return True


outList = []
for line in sys.stdin.readlines():
    List = map(int, line.strip().split())

    [a, b] = List

    # LCM
    LCM = 1
    for i in xrange(2, min(a, b)):
        if not isprime(i): continue
        while(a % i == 0 and b % i == 0):
            LCM *= i
            a /= i
            b /= i

    # GCD
    GCD = List[0] * b

    print LCM, GCD

Submission status: Time Limit Exceeded

Solution code:
import itertools

while 1:
    try:
        a, b= map(int, raw_input().split())
        GCD = a * b
        LCM = 0
        # GCD
        for i, j in itertools.product(range((a if a > b else b) / 2), repeat=2):
          if a * (i+1) == b * (j+1) and GCD > a * (i+1):
            GCD = a * (i+1)
        # LCM 
        for i in range(a if a > b else b, 1, -1):
            if a % i == 0 and b % i == 0:
                LCM = i
                break
        print str(GCD) + " " + str(LCM)
    except:
        break

Submission status: Time Limit Exceeded

Solution code:
import itertools

ans_list = []

while 1:
    try:
        a, b= map(int, raw_input().split())
        GCD = a * b
        LCM = 0
        # GCD
        for i, j in itertools.product(range((a if a > b else b) / 2), repeat=2):
            if a * (i+1) == b * (j+1) and GCD > a * (i+1):
                GCD = a * (i+1)
        # LCM
        for i in range(a if a > b else b, 1, -1):
            if a % i == 0 and b % i == 0:
                LCM = i
                break
        ans_list.append(str(GCD) + " " + str(LCM))
    except:
        for s in ans_list:
            print s
        break

Submission status: Time Limit Exceeded

Solution code:
import itertools

ans_list = []

while 1:
    ab = raw_input()
    if ab != "":
        a, b= map(int, ab.split())
    else:
        for s in ans_list:
            print s
        break
    GCD = a * b
    LCM = 0
    # GCD
    for i, j in itertools.product(range((a if a > b else b) / 2), repeat=2):
        if a * (i+1) == b * (j+1) and GCD > a * (i+1):
            GCD = a * (i+1)
    # LCM
    for i in range(a if a > b else b, 1, -1):
        if a % i == 0 and b % i == 0:
            LCM = i
            break
    ans_list.append(str(GCD) + " " + str(LCM))

Submission status: Time Limit Exceeded

Solution code:
import itertools
import sys

ans_list = []

while 1:
    ab = raw_input()
    if ab != "":
        a, b= map(int, ab.split())
    else:
        for s in ans_list:
            print s
        break
    GCD = a * b
    LCM = 0
    # GCD
    for i, j in itertools.product(range((a if a > b else b) / 2), repeat=2):
        if a * (i+1) == b * (j+1) and GCD > a * (i+1):
            GCD = a * (i+1)
    # LCM
    for i in range(a if a > b else b, 1, -1):
        if a % i == 0 and b % i == 0:
            LCM = i
            break
    ans_list.append(str(GCD) + " " + str(LCM))

sys.exit()

Submission status: Time Limit Exceeded

Solution code:
import itertools

while 1:
    try:
      a, b= map(int, raw_input().split())
    except:
      break
    GCD = a * b
    LCM = 0
    # GCD
    for i, j in itertools.product(range((a if a > b else b) / 2), repeat=2):
        if a * (i+1) == b * (j+1) and GCD > a * (i+1):
            GCD = a * (i+1)
    # LCM
    for i in range(a if a > b else b, 1, -1):
        if a % i == 0 and b % i == 0:
            LCM = i
            break
    print "{} {}".format(str(GCD), str(LCM))

Submission status: Time Limit Exceeded

Solution code:
import itertools

while 1:
    try:
      a, b= map(int, raw_input().split())
    except:
      break
    GCD = a * b
    LCM = 0
    # GCD
    for i, j in itertools.product(range((a if a > b else b) / 2), repeat=2):
        if a * (i+1) == b * (j+1) and GCD > a * (i+1):
            GCD = a * (i+1)
    # LCM
    flag = 0
    for i in range(a if a > b else b, 1, -1):
        if a % i == 0 and b % i == 0 and flag == 0:
            LCM = i
            flag += 1
    print "{} {}".format(str(GCD), str(LCM))

Submission status: Time Limit Exceeded

Solution code:
import itertools

while 1:
    try:
      a, b= map(int, raw_input().split())
      GCD = a * b
      LCM = 0
      # GCD
      for i, j in itertools.product(range((a if a > b else b) / 2), repeat=2):
          if a * (i+1) == b * (j+1) and GCD > a * (i+1):
              GCD = a * (i+1)
      # LCM
      flag = 0
      for i in range(a if a > b else b, 1, -1):
          if a % i == 0 and b % i == 0 and flag == 0:
              LCM = i
              flag += 1
      print "{} {}".format(str(GCD), str(LCM))
    except:
      break

Submission status: Memory Limit Exceeded

Solution code:
import sys
for ab in sys.stdin:
    a,b=map(int,ab.split(" "))
    if a>=b:
        for g in range(b,0,-1):
            if a%g==0 and b%g==0:
                gcd = g
                break
        for l in range(1,b+1):
            if (a*l)%b == 0:
                lcm = a*l
                break
    else:
        for g in range(a,0,-1):
            if a%g==0 and b%g==0:
                gcd = g
                break
        for l in range(1,a+1):
            if (b*l)%a == 0:
                lcm = b*l
                break
    print gcd,lcm

Submission status: Memory Limit Exceeded

Solution code:
import sys

def main():
    for input_line in sys.stdin:
        num1 = int(input_line.split(' ')[0])
        num2 = int(input_line.split(' ')[1])
        
        if num1 <= num2:
            dividend(num1, num2, num1)
        elif num1 > num2:
            dividend(num1, num2, num2)
            
        result.sort(reverse=True)
        greatest_common_divisor = result[0]
        least_common_multiple = num1 * num2 / greatest_common_divisor
        
        print('%s %s' % (greatest_common_divisor, least_common_multiple))
        
def dividend(num1, num2, num):
    for i in range(num):
        divisor = i+1
        if num1 % divisor == 0 and num2 % divisor == 0:
            result.append(divisor)
            
if __name__ == '__main__':
    result = []
    main()

Submission status: Memory Limit Exceeded

Solution code:
import sys

temp = []
largest = 1

for line in sys.stdin:
    a,b = [int(x) for x in line.split()]
    if a > b:
        x,y = a,b
    else:
        x,y = b,a
    for i in list(reversed(range(2, x))):
        if (x % i) == 0 and (y % i) == 0:
            x = x / i
            y = y / i
            largest *= i
    smallest = largest * (a/largest) * (b/largest)
    print('%d %d' % (largest, smallest))
    largest = 1

Submission status: Memory Limit Exceeded

Solution code:
#coding: utf-8

import sys

for line in sys.stdin:
    l = (map(int,line.split()))
    l.sort()
    a = l[0]
    b = l[1]
    for i in range(2,a+1):
        if a%i == 0 and b%i == 0:
            ans = i
    print a*b/ans,ans

Submission status: Memory Limit Exceeded

Solution code:
def calc(a,b):
    yakusuu = []
    for i in range(1, a + 1):
        if a % i == 0:
            yakusuu.append(i)

    maxi = 1
    for j in yakusuu:
        if b % j == 0:
            maxi = j

    mini = maxi * a/maxi * b/maxi
    print maxi, int(mini)

while True:
    try:
        a, b =map(int, raw_input().split())
    except:
        break
    if a > b:
        a, b = b, a # a < b
    calc(a,b)

Submission status: Memory Limit Exceeded

Solution code:
while True:
	a,b = map(int, sorted(raw_input().split()))
	# GCD
	for i in range(a, 1, -1):
		if a%i == 0 and b%i == 0:
			GCD = i
			break
	# LCM
	for i in range(1, a+1):
		print i
		if (b * i) % a == 0:
			LCM = b * i
			break
	print " ".join(map(str,[GCD, LCM]))

Submission status: Memory Limit Exceeded

Solution code:
while True:
	try:
		a,b = map(int, sorted(raw_input().split()))
		# GCD
		for i in range(a, 1, -1):
			if a%i == 0 and b%i == 0:
				GCD = i
				break
		# LCM
		for i in range(1, a+1):
			if (b * i) % a == 0:
				LCM = b * i
				break
		print " ".join(map(str,[GCD, LCM]))
	except EOFError:
		break

Submission status: Memory Limit Exceeded

Solution code:
while True:
	try:
		a,b = map(int, sorted(raw_input().split()))
		# GCD
		for i in range(a, 1, -1):
			if a%i == 0 and b%i == 0:
				GCD = i
				break
		# LCM
		for i in range(1, a+1):
			if (b * i) % a == 0:
				LCM = b * i
				break
		print " ".join(map(str,[GCD, LCM]))[:-1]
	except EOFError:
		break

Submission status: Accepted

Solution code:
import math
while True:
    try:
        a,b=map(int,input().split())
        print(*[math.gcd(a,b),a*b//math.gcd(a,b)])
    except:break

Submission status: Accepted

Solution code:
def gcd(a,b):
    while b != 0:
        a, b = b, a % b
    return a

while True:
    try:
        a, b = map(int, raw_input().split())
        print gcd(a, b), a*b/ gcd(a,b)
    except:
        break

Submission status: Accepted

Solution code:
import math

while True:
    try:
        a,b = map(int,input().split())
        print(math.gcd(a,b),a*b//math.gcd(a,b))
    except:
        break

Submission status: Accepted

Solution code:
def gcd(n1,n2):
    if n2==0:
        return n1
    return gcd(n2,n1%n2)

def lcm(n1,n2):
    return n1/gcd(n1,n2)*n2

while True:
    try:
        a,b=[int(i) for i in input().split()]
        print("{} {}".format(int(gcd(a,b)),int(lcm(a,b))))
    except:
        break

Submission status: Accepted

Solution code:
import sys

while 1:
    line = sys.stdin.readline()
    if (not line):
        break
    x, y = map(int, line.split())
    if (x > y):
        gcd = x
        t = y
    else :
        gcd = y
        t = x
    while (t > 0) :
        tmp = gcd % t
        gcd = t
        t = tmp
    lcm = x * y / gcd
    print str(gcd) + " " + str(lcm)

Submission status: Accepted

Solution code:
import sys

def gcd(a,b):
  if b == 0: return a
  else: return gcd(b,a%b)
  
for i in sys.stdin:
  a, b = map(int, i.split())
  g = gcd(a,b)
  print g, a/g*b

Submission status: Accepted

Solution code:
while True:
    try:
        # a >=b
        a, b = sorted(map(int, input().strip("\n").split(" ")), reverse=True)
        d = a * b

        # calc. gcm by　ユークリッド互除法
        while True:
            c = a % b
            # print("{0} {1} {2}".format(a, b, c))
            if c == 0:
                break
            else:
                a, b = sorted([b, a % b], reverse=True)
        gcm = b
        lcm = d / gcm
        # print("gcm is {}".format(b))
        print("{0:d} {1:d}".format(int(gcm), int(lcm)))

        #print("{0} {1}".format(a, b))
        #a, b = sorted([b, a % b], reverse=True)
        #print("{0} {1}".format(a, b))

    except EOFError:
        break  # escape from while loop

Submission status: Accepted

Solution code:
def GCD(x, y):
    if(x == 0):
        return(y)
    return(GCD(y % x, x))

def LCM(x, y):
    return(x * y / GCD(x, y))

while(True):
    try:
        a = map(int, raw_input().split())
        if(a[0] > a[1]):
            a[0], a[1] = a[1], a[0]
        print(GCD(a[0], a[1])),
        print(LCM(a[0], a[1]))
    except Exception:
        break

Submission status: Accepted

Solution code:
while True:
	try:
		[x, y] = map(int, raw_input().split())
		if x < y:
			a = y
			b = x
		else:
			a = x
			b = y
		while a % b:
			c = a % b
			a = b
			b = c
		print "%d %d" % (b, x*y/b)
	except (EOFError):
		break

Submission status: Accepted

Solution code:
import sys

def gcd(a,b):
	while a%b :
		a,b=b,a%b
	return b
	
def lcm(a,b) :
	return a*b/gcd(a,b)
	
for ab in sys.stdin:
	a,b = map(int,ab.split())
	a,b = max(a,b),min(a,b)
	print "%d" % gcd(a,b),
	print "%d" % lcm(a,b)

Submission status: Accepted

Solution code:
import sys
for line in sys.stdin:
    a, b = map(int, line.split())
    A, B = min(a, b), max(a, b)

    while True:
        mod = B % A
        if mod == 0:
            gcd = A
            break
        else:
            A, B = mod, A
    lcm = gcd * (a / gcd) * (b / gcd)

    print '%d %d' % (gcd, lcm)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys

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

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

for s in sys.stdin:
  d = map(int, s.split())
  a,b = d[0],d[1]
  print gcd(a,b),lcm(a,b)

Submission status: Accepted

Solution code:
def gcd(n, m):
    while n!=0:
        tmp = n
        n = m % n
        m = tmp
    return m

while 1:
    try:
        n, m = map(int, input().split())
        x = gcd(n, m)
        print(x, int(n*m/x))
    except EOFError:
        break

Submission status: Accepted

Solution code:
def gcd(n, m):
    while n:
        n, m = m % n, n
    return m

while 1:
    try:
        n, m = map(int, input().split())
        g = gcd(n, m)
        print(g, int(n*m/g))
    except EOFError:
        break

Submission status: Accepted

Solution code:
def gcd(a, b):
    while b: 
    	a, b = b, a % b
    return a
 
while True:
    try:
        line = input()
    except:
        break
    a, b = map(int, line.strip().split())
    g = gcd(a, b)
    print(g, a * b // g)

Submission status: Accepted

Solution code:
while 1:
    try:
        a, b = map(int, raw_input().split())
        if a > b: x, y = a, b
        else: x, y = b, a

        r = x % y
        while (r != 0):
            x = y
            y = r
            r = x % y
        gcd = y

        lcm = (a / gcd) * b

        print str(gcd) + " " + str(lcm)

    except:
        break

Submission status: Accepted

Solution code:
def gcd(a,b):
	while b: a,b=b,a%b
	return a
while True:
	try:
		a,b = map(int,input().split())
		print(gcd(a,b),a*b//gcd(a,b))
	except:
		break;

Submission status: Accepted

Solution code:
import sys


def gcd(n, m):
    while m:
        n, m = m, n % m
    return n


def lcm(x, y):
    return int((x * y) / gcd(x, y))

for line in sys.stdin:
    l = line.replace('\n', '')
    a, b = l.split()
    a = int(a)
    b = int(b)
    print(gcd(a, b), lcm(a, b))

Submission status: Accepted

Solution code:
while True:
    try:
        a,b=map(int,input().split())
        y=a*b
        if b>a:
            a,b=b,a
        
        while a%b:
            x=a
            a,b=b,x%b

        print(b,int(y/b))

    except:
        break

Submission status: Accepted

Solution code:
import sys

#最大公約数
def gcd(x, y):
    s = x / y
    r = x % y
    if r == 0:
        return y
    else:
        return gcd(y, r)

#最小公倍数
def lcm(x, y):
    return x*y/gcd(x, y)

def main():
    #print ("a")
    for line in iter(sys.stdin.readline, ""):
        #print (line)
        #tmp = sys.stdin.readline().split(" ")
        #print ("b")
        tmp = line.split(" ")
    
        a = int(tmp[0])
        b = int(tmp[1])
        #print ("a="+str(a))
        #print ("b="+str(b))
        #b = sys.stdin.readline()
        #print ("d")
        if a > b:
            c = a
            d = b
        else:
            c = b
            d = a

        print (str(gcd(c, d)) + " " + str(int(lcm(c,d))))

        #tmp = sys.stdin.readline()
        #if len(tmp) == 1:
        #    break
        #else:
        #    tmp = tmp.split(" ")

    #print ("exit")
     
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
while(1):
    try:
        i = raw_input()
        a, b = map(int, i.split())
        x, y = a, b
        while(b != 0):
            tmp = b
            b = a % b
            a = tmp
        print a,
        print x*y/a
    except:
        break

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys

def gcd(a,b):
    while a%b:
        a,b = b,a%b
    return b

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

for s in sys.stdin:
    a,b = map(int,s.split())
    a,b = max(a,b),min(a,b)
    print gcd(a,b),lcm(a,b)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import fractions

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

for s in sys.stdin:
    a,b = map(int,s.split())
    gcd_ab = fractions.gcd(a,b)
    lcm_ab = lcm(a,b)

    print gcd_ab,lcm_ab

Submission status: Accepted

Solution code:
import sys

def gcd(a, b):
    while b % a:
        a, b = b % a, a
    return a
def lcm(a, b):
    return a * b // gcd(a, b)

for line in sys.stdin:
    a, b = sorted(list(map(int, line.split())))
    print(gcd(a, b), lcm(a, b))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from fractions import gcd

for line in sys.stdin:
    [a, b] = [int(x) for x in line.split()]
    print(int(gcd(a, b)), int(a / gcd(a, b) * b))

Submission status: Accepted

Solution code:
def gcd(m,n):  
    while m%n>0:
        m,n=n,m%n
    else:
        return n

while True:
    try:    
        a,b = map(int,raw_input().split())
        a,b = max(a,b),min(a,b)
        g = gcd(a,b)
        l = a*b/g
        print "%d %d" % (g, l)
    except EOFError: 
        break

Submission status: Accepted

Solution code:
#! /usr/lib/python3

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

while True:
    try:
        a, b=map(int, input().split())
        s=gcd(a,b)
        print("{0} {1:.0f}".format(s,a*b/s))
    except:
        break

Submission status: Accepted

Solution code:
#! /usr/lib/python3
import fractions
while True:
    try:
        a, b=map(int, input().split())
        s=fractions.gcd(a,b)
        print("{0} {1:.0f}".format(s,a*b/s))
    except:
        break

Submission status: Accepted

Solution code:
import sys
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
def lcm(a, b):
	return a * b // gcd (a, b)

for line in sys.stdin.readlines():
    num = map(int, line.strip().split())
    print "%i %i"%(gcd(num[0],num[1]) , lcm(num[0],num[1]))

Submission status: Accepted

Solution code:
while True:
	try:
		temp = [int(x) for x in raw_input().split()]
		m = max(temp)
		n = min(temp)

		while True:
			if n == 0:
				print m, (temp[0]*temp[1])/m
				break
			else:
				temp2 = n
				n = m % n
				m = temp2

	except:
		break

Submission status: Accepted

Solution code:
def GCD(a,b):
    if b == 0:
        return a
    else:
        r = a % b
        return GCD(b, r)
        
while True:
    try:
        data = map(int, raw_input().split())
    except:
        break
    if data[0] > data[1]:
        a = data[0]
        b = data[1]
    else:
        a = data[1]
        b = data[0]
    x = GCD(a, b)
    y = a*b / x
    
    print x, y

Submission status: Accepted

Solution code:
def gcd(a,b):
	while a>0 and b>0:
		if a<b:
			b -= a
		elif a>b:
			a -= b
		else:
			return a
	raise

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


while True:
	try:
		inp = raw_input()
	except EOFError:
		break
	a, b = map((lambda x: int(x) ), inp.split())

	print gcd(a,b),lcm(a,b)

Submission status: Accepted

Solution code:
import sys

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

for ab in sys.stdin:
    a,b=map(int,ab.split(" "))
    if a<=b:
        tmp = a
        a = b
        b = tmp
    g = gcd(a,b)
    l = a*b/g
    print g,l

Submission status: Accepted

Solution code:
while True:
    try:
        spam=map(int, input().split(' '))
        spam = [i for i in spam]
        spam.sort()
        cola = spam[0] * spam[1]
        while True:
            if spam[0] == 0:
                print('{} {}'.format(spam[1],int(cola/spam[1])))
                break
            pre = spam[0]
            spam[0] = spam[1] % spam[0]
            spam[1] = pre
    except:
        break

Submission status: Accepted

Solution code:
def gcd(a,b):
    r = a % b
    while r > 0:
        a = b
        b = r
        r = a % b
    return b

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

while True:
    try:
        a,b = map(int, raw_input().split())
        print str(gcd(a,b)) + " " + str(lcm(a,b))
    except EOFError:
        break

Submission status: Accepted

Solution code:
# coding: utf-8

import sys

def gcd(a, b):
    while a % b:
        a, b = b, a%b
    return b

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

for n in sys.stdin:
    a, b = map(int, n.split())
    a, b = max(a, b), min(a,b)
    print gcd(a, b), lcm(a, b)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

while True:
  try:
    ( a, b ) = map ( int, input ( ).split ( ) )
  except EOFError: break
  ( x, y ) = ( a, b )
  while x != 0:
    ( x, y ) = ( y % x, x )
  print ( "%s %s" % ( y, a * b // y ) )

Submission status: Accepted

Solution code:
import sys
for n in sys.stdin:
	l=map(int,n.split())
	b=l[0]*l[1]
	u=[max(l),min(l)]
	while u[1]!=0:
		u=[u[1],u[0]%u[1]]
	print "%d %d"%(u[0],b/u[0])

Submission status: Accepted

Solution code:
import sys
for n in sys.stdin:
	u=map(int,n.split())
	b=u[0]*u[1]
	while u[1]!=0:u=[u[1],u[0]%u[1]]
	print "%d %d"%(u[0],b/u[0])

Submission status: Accepted

Solution code:
import sys
for n in sys.stdin:
	u=map(int,n.split())
	b=u[0]*u[1]
	while u[1]!=0:u=[u[1],u[0]%u[1]]
	print"%d %d"%(u[0],b/u[0])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

while(True):
	try:
		a,b=map(int, input().split())
	except EOFError:
		break

	#euclidian algorithm	
	r=a%b
	x,y=a,b
	while(r>0):
		x=y
		y=r
		r=x%y
	gcd=y
	lcm=int(a*b/gcd)
	print("{0} {1}".format(gcd, lcm))

Submission status: Accepted

Solution code:
import sys

def dividend(num, Q):
    a = Q
    b = (num / Q) * Q
    Q = num - (num / Q) * Q
    if num  == b:
        aaa(a)
        return
    dividend(a, Q)
    
def aaa(greatest_common_divisor):
    least_common_multiple = num1 * num2 / greatest_common_divisor
    print('%s %s' % (greatest_common_divisor, least_common_multiple))
    return

for input_line in sys.stdin:
    num1 = int(input_line.split(' ')[0])
    num2 = int(input_line.split(' ')[1])
    
    if num1 <= num2:
        dividend(num2, num1)
    elif num1 > num2:
        dividend(num1, num2)

Submission status: Accepted

Solution code:
def GCD_cal(a,b):
	if(b==0):
		return(a)
	a,b=b,a%b
	return(GCD_cal(a,b))

while(True):
	try:
		a,b=map(int,input().split(" "))
	except:
		break
	if(a<b):
		a,b=b,a
	GCD=GCD_cal(a,b)
	LCM=int(a*b/GCD)
	print("{0} {1}".format(GCD,LCM))

Submission status: Accepted

Solution code:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

while True:
    try:
        a, b = map(int, input().split())
        print(gcd(a, b), a * b // gcd(a, b))
    except:
        break

Submission status: Accepted

Solution code:
# coding: utf-8
#Problem Name: GCD and LCM
#ID: tabris
#Mail: t123037@kaiyodai.ac.jp

while True:
    try:
        a,b = map(int,raw_input().split(' '))
        s,t = a,b
        while True:
            r = s % t
            if not r:
                LCM = t
                break
            else:
                s,t = t,r
        
        print LCM, a*b/LCM
    except:
        break

Submission status: Accepted

Solution code:

def gcd(a, b):
    """Return greatest common divisor using Euclid's Algorithm."""
    while b:      
        a, b = b, a % b
    return a

def lcm(a, b):
    """Return lowest common multiple."""
    return a * b // gcd(a, b)

try:
 while True:
  a, b = map(int, raw_input().split(' '))
  print gcd(a, b), lcm(a, b)
except EOFError:
  pass

Submission status: Accepted

Solution code:
def gcd(a,b): return a if b==0 else gcd(b,a%b)
def lcm(a,b): return a*b/gcd(a,b)

while 1:
    try:
        a,b=map(int,raw_input().split())
        print gcd(a,b),lcm(a,b)
    except:
        break

Submission status: Accepted

Solution code:
import sys

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a


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

for line in sys.stdin:
	a, b = map(int , line.split())
	print gcd(a,b), lcm(a,b)