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
.
r
as the negation of the realr
for languages that uses unsigned bytes to store data or assume overflowing? (-1
→1
/255
) \$\endgroup\$