mx_02_3_c.py

Created by lorem-ipsum-42

Created on November 21, 2021

562 Bytes


def div_euc1(a, b, q=0):
  start_a = a
  is_neg = 1
  div_pos_uniq = False
  if a<0 and b<0:
    b = -b
    a = -a
  if b < 0:
    b = -b
    div_pos_uniq = True
  if a < 0:
    a =-a
    is_neg = -1
  q = 0
  while not a<b:
    a -= b
    q += 1
  if is_neg==-1 and a != 0:
    q += 1
    a = b - a
  if div_pos_uniq:
    if a == 0:
      q = - q
    else:
      a = b - a
  return (q*is_neg, a)
    
liste= [(120,24),(-120,24),(120,-24),(-120,-24),(120,42),(-120,42),(120,-42),(-120,-42)]

for elem in liste:
  print(div_euc1(elem[0],elem[1]))

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.