13
Task
Given two positive integers (dividend and divisor), calculate the quotient and the remainder.
Normally it would be calculated as e = o*q+r
where q*o<=e
and 0<=r<o
.
For this challenge it still e = o*q+r
but q*o>=e
and -o<r<=0
.
For example e=20
and o=3
, normally it would be 20/3 -> 20=3*6+2
, since 18<=20
and 0<=2<3
. Here it will be 20/3 -> 20=3*7-1
where 21>=20
and -3<-1<=0
Test Cases
Input -> Output
20, 3 -> 7, -1
10, 5 -> 2, 0
7, 20 -> 1, -13
100, 13 -> 8, -4
You don't need to handle o=0
.
3Called it on being a trivial variant of regular divmod. – Neil – 2017-12-11T14:54:36.340
Is it acceptable to output
r
as the negation of the realr
for languages that uses unsigned bytes to store data or assume overflowing? (-1
→1
/255
) – Uriel – 2017-12-11T15:12:59.267@Uriel yes, but add a note about this on the answer – Rod – 2017-12-11T15:14:54.917