Résout une division euclidienne.
def diveuc(a, b): # a = dividende, b = diviseur q = 0 if b == 0: raise ValueError("on ne peut pas diviser pas 0") elif a == 0: return (0, 0) elif a > 0 and b > 0: r = a while b <= r: r -= b q += 1 return (q, r) elif a < 0 and b > 0: r = -a while b <= r: r -= b q -= 1 if r != 0: q -= 1 r = abs(r - b) return (q, r) elif a > 0 and b < 0: r = a while -b <= r: r -= -b q -= 1 return (q, r) else: r = -a while -b <= r: r -= -b q += 1 if r != 0: q += 1 r = abs(r + b) return (q, r) def diveuc_fraude(a, b): if b == 0: raise ValueError("on ne peut pas diviser pas 0") elif a == 0: return (0, 0) elif b > 0: return (a//b, a%b) elif b < 0: return ((a//b) + 1, (a%b) - b) if a%b != 0 else (a//b, a%b)