summaryrefslogtreecommitdiff
path: root/PlaygroundCpp/Sources
diff options
context:
space:
mode:
authorHaidong Ji2018-08-19 19:47:51 -0500
committerHaidong Ji2018-08-19 19:47:51 -0500
commit13823672a0b4c014abeb3f77145328576059fa9f (patch)
treed7996872ba5478b424a825c49543d0c48dd7ef91 /PlaygroundCpp/Sources
parent1b625dab2d7b56e6b8d3289a0726724b3830e6b7 (diff)
LCM done!
Diffstat (limited to 'PlaygroundCpp/Sources')
-rw-r--r--PlaygroundCpp/Sources/Playground.cpp31
1 files changed, 12 insertions, 19 deletions
diff --git a/PlaygroundCpp/Sources/Playground.cpp b/PlaygroundCpp/Sources/Playground.cpp
index caa008b..2986140 100644
--- a/PlaygroundCpp/Sources/Playground.cpp
+++ b/PlaygroundCpp/Sources/Playground.cpp
@@ -12,34 +12,27 @@ static int getGCD(int a, int b) {
return getGCD(b, a % b);
}
}
-//TEST(FibLastDigitTest, Zero) {
-// ASSERT_EQ(getGCD(18, 35), 1);
-//}
-//
-//TEST(FibLastDigitTest, One) {
-// ASSERT_EQ(17657, getGCD(28851538, 1183019));
-//}
-//
-//TEST(FibLastDigitTest, Three) {
-// ASSERT_EQ(7, getGCD(1344, 217));
-//}
-//
-//TEST(FibLastDigitTest, Forty) {
-// ASSERT_EQ(1344, getGCD(1344, 1344));
+static long getLCM(int a, int b) {
+ // https://www.idomaths.com/hcflcm.php#formula
+ return (long) a * (long) b / (long) getGCD(a, b);
+}
+
+//TEST(LCMTest, Zero) {
+// ASSERT_EQ(getLCM(6, 8), 24);
//}
//
-//TEST(FibLastDigitTest, ThreeThreeOne) {
-// ASSERT_EQ(4, getGCD(14159572, 63967072));
+//TEST(LCMTest, One) {
+// ASSERT_EQ(getLCM(28851538, 1183019), 1933053046);
//}
//
-//TEST(FibLastDigitTest, ReverseAB) {
-// ASSERT_EQ(4, getGCD(14159572, 63967072));
+//TEST(LCMTest, Two) {
+// ASSERT_EQ(getLCM(14159572, 63967072), 226436590403296);
//}
int main() {
int a, b;
std::cin >> a;
std::cin >> b;
- int c = getGCD(a, b);
+ long c = getLCM(a, b);
std::cout << c << '\n';
}