From 13823672a0b4c014abeb3f77145328576059fa9f Mon Sep 17 00:00:00 2001 From: Haidong Ji Date: Sun, 19 Aug 2018 19:47:51 -0500 Subject: LCM done! --- PlaygroundCpp/Sources/Playground.cpp | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) (limited to 'PlaygroundCpp/Sources') 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'; } -- cgit v1.2.3