Calculating GCD Using Euclidean Algorithm

  • Share this:

Code introduction


This function calculates the Greatest Common Divisor (GCD) of two integers using the Euclidean algorithm.


Technology Stack : Built-in functions (% for modulus operation; while loop for iteration)

Code Type : Function

Code Difficulty :


                
                    
def arial(arg1, arg2):
    """
    计算两个数的最大公约数(GCD)。
    """
    while arg2:
        arg1, arg2 = arg2, arg1 % arg2
    return arg1