diff options
-rw-r--r-- | AlgoDesignAndTechniqueEdxPython/sources/gcdlcm.py (renamed from AlgoDesignAndTechniqueEdxPython/sources/gcd.py) | 5 | ||||
-rw-r--r-- | AlgoDesignAndTechniqueEdxPython/tests/gcdlcmTest.py (renamed from AlgoDesignAndTechniqueEdxPython/tests/gcdTest.py) | 7 |
2 files changed, 10 insertions, 2 deletions
diff --git a/AlgoDesignAndTechniqueEdxPython/sources/gcd.py b/AlgoDesignAndTechniqueEdxPython/sources/gcdlcm.py index 7b107cd..57b48ff 100644 --- a/AlgoDesignAndTechniqueEdxPython/sources/gcd.py +++ b/AlgoDesignAndTechniqueEdxPython/sources/gcdlcm.py @@ -10,10 +10,13 @@ def getGCD(a, b): else: return getGCD(b, a % b) +def getLCM(a, b): +# https://www.idomaths.com/hcflcm.php#formula + return a * b // getGCD(a, b) if __name__ == '__main__': entryNumbers = sys.stdin.read() tokens = entryNumbers.split() a = int(tokens[0]) b = int(tokens[1]) - print(getGCD(a, b)) + print(getLCM(a, b))
\ No newline at end of file diff --git a/AlgoDesignAndTechniqueEdxPython/tests/gcdTest.py b/AlgoDesignAndTechniqueEdxPython/tests/gcdlcmTest.py index a41b49e..82a7295 100644 --- a/AlgoDesignAndTechniqueEdxPython/tests/gcdTest.py +++ b/AlgoDesignAndTechniqueEdxPython/tests/gcdlcmTest.py @@ -5,7 +5,7 @@ Created on Aug 19, 2018 ''' import unittest -from sources.gcd import getGCD +from sources.gcdlcm import getGCD, getLCM class Test(unittest.TestCase): @@ -18,6 +18,11 @@ class Test(unittest.TestCase): self.assertEqual(4, getGCD(14159572, 63967072)) self.assertEqual(4, getGCD(63967072,14159572)) + def testLCM(self): + self.assertEqual(24, getLCM(6, 8)) + self.assertEqual(1933053046, getLCM(28851538, 1183019)) + self.assertEqual(226436590403296, getLCM(14159572, 63967072)) + self.assertEqual(46374212988031350, getLCM(226553150, 1023473145)) if __name__ == "__main__": #import sys;sys.argv = ['', 'Test.testName'] |