Integer math question

Sean Ross sross at connectmail.carleton.ca
Sat Jan 3 16:31:17 EST 2004


"Sean Ross" <sross at connectmail.carleton.ca> wrote in message
news:5sFJb.20923$Vl6.3818930 at news20.bellglobal.com...
> "Rainer Deyke" <rainerd at eldwood.com> wrote in message
> news:kTEJb.724242$HS4.5376202 at attbi_s01...
> >>> a = 5
> >>> b = -10
> >>> q,r = divmod(a,b)
> >>> q
> -1
> >>> r
> -5
> >>>
>
> Here, the division algorithm does not apply (b is a negative integer).
> Perhaps there's some other theorem for this case?
> b<r<=0, when b < 0? I don't know.
>

I think you're supposed to do something like this
a = bq + r,      0<= r < |b|
5 = (-10)q + r
-5 = -(-10)q - r
-5 = 10q - r

But, then, q would be 0 and r would be 5. <shrug>






More information about the Python-list mailing list