#K52237. Integer Division Without Using /, *, and % Operators
Integer Division Without Using /, *, and % Operators
Integer Division Without Using /, *, and % Operators
In this problem, you are required to implement integer division without using the operators ( / ), ( * ), or ( % ). Given two integers, the dividend and the divisor, your task is to compute the quotient and the remainder using only addition, subtraction, and bit shifting operations. The algorithm must handle both positive and negative numbers correctly. In particular, the remainder must always be non-negative and less than the absolute value of the divisor.
For example:
(10 \div 3 = 3) with remainder (1).
(7 \div -3 = -2) with remainder (1).
(-17 \div 4 = -4) with remainder (3).
inputFormat
The input is read from standard input (stdin) as two space-separated integers: the dividend and the divisor. You may assume that the divisor is non-zero.
outputFormat
Output the quotient and the remainder separated by a space on a single line to standard output (stdout).## sample
10 3
3 1