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.
- Program for quotient and remainder of big number
- First number to leave an odd remainder after repetitive division by 2
- Write you own Power without using multiplication(*) and division(/) operators
- Multiply two integers without using multiplication, division and bitwise operators, and no loops
- Minimum integer such that it leaves a remainder 1 on dividing with any element from the range [2, N]
- Implementation of Non-Restoring Division Algorithm for Unsigned Integer
- Implementation of Restoring Division Algorithm for unsigned integer
- Find permutation with maximum remainder Sum
- Find the remainder when N is divided by 4 using Bitwise AND operator
- Program to find remainder without using modulo or % operator
- Find numbers that divide X and Y to produce the same remainder
- Program to find remainder when large number is divided by 11
- Program to find remainder when large number is divided by r
- Find the number after successive division
- Find two numbers with difference and division both same as N
- Long Division Method to find Square root with Examples
- Find the remainder when First digit of a number is divided by its Last digit
- Find whether a given integer is a power of 3 or not
- Find One's Complement of an Integer
- Count of divisors having more set bits than quotient on dividing N
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.