About 50 results
Open links in new tab
  1. Code for Greatest Common Divisor in Python - Stack Overflow

    Jun 24, 2012 · The greatest common divisor (GCD) of a and b is the largest number that divides both of them with no remainder. One way to find the GCD of two numbers is Euclid’s algorithm, which is …

  2. Euclidean Algorithm / GCD in Python - Stack Overflow

    Sep 19, 2015 · I'm trying to write the Euclidean Algorithm in Python. It's to find the GCD of two really large numbers. The formula is a = bq + r where a and b are your two numbers, q is the number of …

  3. How to find greatest common divisor using recursive function in …

    Dec 2, 2019 · I am asked to find the greatest common divisor of integers x and y using a recursive function in Python. The condition says that: if y is equal to 0 then gcd (x,y) is x; otherwise gcd (x,y) is …

  4. algorithm - Python gcd for list - Stack Overflow

    Mar 22, 2015 · 38 As of python 3.9, python got built-in support for calculating gcd over a list of numbers.

  5. python - Euclidean algorithm (GCD) with multiple numbers ... - Stack ...

    def GCD(numbers): if numbers[-1] == 0: return numbers[0] # i'm stuck here, this is wrong for i in range(len(numbers)-1): print GCD([numbers[i+1], numbers[i] % numbers[i+1]]) print GCD(30, 40, 36) …

  6. Built-in module to calculate the least common multiple

    In Python 3.8 and earlier There is no such thing built into the stdlib. However, there is a Greatest Common Divisor function in the math library. (For Python 3.4 or 2.7, it's buried in fractions instead.) …

  7. python - How to find lcm of two numbers efficiently (With out using …

    Jun 2, 2022 · You can find the lcm using the gcd with this formula. The gcd can be found efficiently with the euclidean algorithm

  8. Calculate the LCM of a list of given numbers in Python

    May 15, 2016 · For example, np.lcm.reduce ( [2028, 5898, 4702]) gives the answer 391807628, which is not correct (tested using the most recent Anaconda distributions for Python 2.7 and 3.7). Using …

  9. Least common multiple for 3 or more numbers - Stack Overflow

    Sep 29, 2008 · But have no idea how to expand it to calculate 3 or more numbers. So far this is how I did it LCM = num1 * num2 / gcd ( num1 , num2 ) With gcd is the function to calculate the greatest …

  10. python - How to find the GCD/HCF of three numbers in Python3

    I need a code to find the common prime factors of three numbers in Python 3 Whenever I run it shows me the wrong HCF / GCD.