Given two positive integers dividend and divisor, our task is to find quotient and remainder. The use of division or mod operator is not allowed.
Input : dividend = 10, divisor = 3
Output : 3, 1
The quotient when 10 is divided by 3 is 3 and the remainder is 1.
Input : dividend = 11, divisor = 5
Output : 2, 1
The quotient when 11 is divided by 5 is 2 and the remainder is 1.
To solve the problem mentioned above we will use the Binary Search technique. We can implement the search method in range 1 to N where N is the dividend. Here we will use multiplication to decide the range. As soon as we break out of the while loop of binary search we get our quotient and the remainder can be found using the multiplication and subtraction operator. Handle the special case, when the dividend is less than or equal to the divisor, without the use of binary search.
Below is the implementation of the above approach:
Time Complexity: O(logN)
Space Complexity: O(n)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Multiply two integers without using multiplication, division and bitwise operators, and no loops
- Program for quotient and remainder of big number
- Write you own Power without using multiplication(*) and division(/) operators
- Divide two integers without using multiplication, division and mod operator | Set2
- First number to leave an odd remainder after repetitive division by 2
- Program to find remainder without using modulo or % operator
- Add two numbers without using arithmetic operators
- How to sum two integers without using arithmetic operators in C/C++?
- Largest of two distinct numbers without using any conditional statements or operators
- Division without using '/' operator
- Minimum integer such that it leaves a remainder 1 on dividing with any element from the range [2, N]
- Implementation of Restoring Division Algorithm for unsigned integer
- Implementation of Non-Restoring Division Algorithm for Unsigned Integer
- Check if a number is multiple of 5 without using / and % operators
- Find two numbers with difference and division both same as N
- Find the remainder when N is divided by 4 using Bitwise AND operator
- Count of divisors having more set bits than quotient on dividing N
- C++ program to divide a number by 3 without using *, / , +, -, % operators
- Decimal to binary conversion without using arithmetic operators
- Find numbers that divide X and Y to produce the same remainder
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.