-
Notifications
You must be signed in to change notification settings - Fork 0
/
BCGCD.c
40 lines (32 loc) · 1.22 KB
/
BCGCD.c
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
#include <stdio.h>
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;
scanf("%lld %lld", &firstNumber, &secondNumber);
if ((firstNumber == 0) && (secondNumber == 0))
{
break;
}
long long greatestCommonDivisor = calculateGreatestCommonDivisor(firstNumber, secondNumber);
long long leastCommonMultiple = calculateLeastCommonMultiple(firstNumber, secondNumber, greatestCommonDivisor);
printf("%lld %lld\n", greatestCommonDivisor, leastCommonMultiple);
}
}
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;
}