summaryrefslogtreecommitdiff
path: root/AlgoDesignAndTechniqueEdxPython/sources/gcdlcm.py
diff options
context:
space:
mode:
Diffstat (limited to 'AlgoDesignAndTechniqueEdxPython/sources/gcdlcm.py')
-rw-r--r--AlgoDesignAndTechniqueEdxPython/sources/gcdlcm.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/AlgoDesignAndTechniqueEdxPython/sources/gcdlcm.py b/AlgoDesignAndTechniqueEdxPython/sources/gcdlcm.py
new file mode 100644
index 0000000..57b48ff
--- /dev/null
+++ b/AlgoDesignAndTechniqueEdxPython/sources/gcdlcm.py
@@ -0,0 +1,22 @@
+# Uses python3
+import sys
+
+
+def getGCD(a, b):
+ if b == 0:
+ return a
+ if b > a:
+ return getGCD(b, a)
+ 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(getLCM(a, b)) \ No newline at end of file