We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 62651e1 commit d0895a6Copy full SHA for d0895a6
pygorithm/math/lcm_using_gcd.py
@@ -0,0 +1,32 @@
1
+# Author: Ashutosh Gupta
2
+# Created On: 8/17/2017
3
+# Time: 10:03 PM
4
+
5
6
+def gcd(x, y):
7
+ """
8
+ Function to find gcm (greatest common divisor) of two numbers
9
+ :param x: first number
10
+ :param y: second number
11
+ :return: gcd of x and y
12
13
+ while y != 0:
14
+ (x, y) = (y, x % y)
15
+ return x
16
17
18
+def lcm_using_gcd(List):
19
+ """ function to find LCM for given list of elements
20
21
+ :param List: List of which LCM is to be found out
22
23
+ lcm = List[0]
24
+ for element in List:
25
+ lcm = lcm * element / gcd(lcm, element)
26
27
+ return lcm
28
29
+def get_code():
30
+ """ returns the code for the current class """
31
+ import inspect
32
+ return inspect.getsource(lcm_using_gcd)
0 commit comments