mx_02_iii_c.py

Created by lorem-ipsum-42

Created on November 21, 2021

658 Bytes


def div_euc(a, b):
    q = 0
    if a > 0 and b > 0:
        while a >= b:
            a -= b
            q += 1
        return (q, a)
    else:
        temp_a = a
        temp_b = b
        if temp_a < 0:
            temp_a = - temp_a
        if temp_b < 0:
            temp_b = - temp_b
        while temp_a >= temp_b:
            temp_a -= temp_b
            q += 1
        if temp_a != 0:    
          q += 1
          temp_a = temp_b - temp_a
        if a < 0 and b < 0:
          return(q, temp_a)
        elif (a < 0 and not b < 0) or (b<0 and not a < 0):
            return(-q, temp_a)
        else:
            return(-q, temp_a)

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.