Given two integers say a and b. Find the quotient after dividing a by b without using multiplication, division and mod operator.
Input: a = 10, b = 3 Output: 3 Input: a = 43, b = -8 Output: -5
This problem has been already discussed here. In this post, a different approach is discussed.
- Let a/b = c.
- Take log on both sides
- log(a) – log(b) = log(c)
- Now Log of RHS can be written as exp in LHS
- Final formula is : exp(log(a) – log(b)) = c
10 / 5 is equal to : 2 49 / -7 is equal to : -7
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
- Write you own Power without using multiplication(*) and division(/) operators
- Division without using '/' operator
- Trick for modular division ( (x1 * x2 .... xn) / b ) mod (m)
- Minimum steps to convert X to Y by repeated division and multiplication
- Find Quotient and Remainder of two integer without using division operators
- Smallest string without any multiplication sign that represents the product of two given numbers
- To find sum of two numbers without using any operator
- Decimal to Binary using recursion and without using power operator
- How to sum two integers without using arithmetic operators in C/C++?
- C++ program to divide a number by 3 without using *, / , +, -, % operators
- Count of integers that divide all the elements of the given array
- Program to find remainder without using modulo or % operator
- Maximum OR value of a pair in an Array without using OR operator
- Find two numbers with difference and division both same as N
- Number of digits before the decimal point in the division of two numbers
- Maximum value of division of two numbers in an Array
- Count number of solutions of x^2 = 1 (mod p) in given range
- Find power of power under mod of a prime
- How to compute mod of a big number?
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.