Write a program that asks the user to enter two integers, then calculates and displays their greatest common divisor (GCD) and their Least common multiple (LCM).
寫一個輸入兩個整數 輸出它們的最大公因數程式
Hint: Use Euclidean Algorithm
使用歐幾里得演算法
LCM:
In arithmetic and number theory, the least common multiple, lowest common multiple, or smallest common multiple of two integers a and b, usually denoted by LCM(a, b), is the smallest positive integer that is divisible by both a and b.
What is the LCM of 4 and 6?
Multiples of 4 are:
4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, ...
and the multiples of 6 are:
6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, ...
Common multiples of 4 and 6 are simply the numbers that are in both lists:
12, 24, 36, 48, 60, 72, ....
So, from this list of the first few common multiples of the numbers 4 and 6, their least common multiple is 12.
Example input:
12 28
Example output (first number is GCD, second number is LCM):
4 84