-
Notifications
You must be signed in to change notification settings - Fork 0
/
BCGCD.cpp
42 lines (33 loc) · 1.23 KB
/
BCGCD.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
using namespace std;
long long calculateGreatestCommonDivisor(long long firstNumber, long long secondNumber);
long long calculateLeastCommonMultiple(long long firstNumber, long long secondNumber, long long greatestCommonDivisor);
int main()
{
while(1)
{
long long firstNumber, secondNumber;
cin >> firstNumber >> secondNumber;
if ((firstNumber == 0) && (secondNumber == 0))
{
break;
}
long long greatestCommonDivisor = calculateGreatestCommonDivisor(firstNumber, secondNumber);
long long leastCommonMultiple = calculateLeastCommonMultiple(firstNumber, secondNumber, greatestCommonDivisor);
cout << greatestCommonDivisor << " " << leastCommonMultiple << endl;
}
}
long long calculateGreatestCommonDivisor(long long firstNumber, long long secondNumber)
{
while (secondNumber != 0)
{
long long temp = secondNumber;
secondNumber = firstNumber % secondNumber;
firstNumber = temp;
}
return firstNumber;
}
long long calculateLeastCommonMultiple(long long firstNumber, long long secondNumber, long long greatestCommonDivisor)
{
return firstNumber * secondNumber / greatestCommonDivisor;
}