BOJ 5347 LCM


https://www.acmicpc.net/problem/5347
時間1秒、メモリ128 MB
input :
  • n
  • a b
  • output :
  • 出力2つの最小公倍数
  • さっきと同じです.
    tempに最大公約数を2つ格納します.
    a//temp値、b/temp値に最大公約数を乗じる.
    import sys
    
    
    def gcd(a, b):
        if b == 0:
            return a
        return gcd(b, a % b)
    
    
    t = int(sys.stdin.readline())
    for i in range(t):
        a, b = map(int, sys.stdin.readline().split())
        temp = gcd(a, b)
        print(temp * a // temp * b // temp)