6

Divide Two Integers

Difficulty: EASY
Contributed By
Avg. time to solve
10 min
Success Rate
90%

Problem Statement

You are given two integers ‘dividend’ and ‘divisor’. You are required is to divide the integers without using multiplication, division and modular operators. Your task is to return the quotient after dividing ‘dividend’ by ‘divisor’.

Note :

In cases where the dividend is not perfectly divisible by the divisor, you are required to return the floored value of the quotient.

For example :

If the answer is ‘9.333’ then return ‘9’ or if the answer is ‘-8.123’ then return ‘-8’.
Input format:
The first line of input contains an integer ‘T’ denoting the number of test cases.

The next ‘T’ lines represent the ‘T’ test cases.

The first line of every test case contains two space-separated integers ‘dividend’ and ‘divisor’. 
Output Format
For each test case, return the floor value of the quotient.

Output for each test case will be printed in a separate line.
Note:
You do not need to print anything, it has already been taken care of. Just implement the given function.
Constraints:
1 <= T <= 10^5
-10^9 <= dividend, divisor <= 10^9 
divisor != 0  

Time limit: 1 second
Sample Input 1:
2
10 3
-9 2
Sample Output 1:
3
-4
Explanation of sample input 1:
In test Case 1:

Given ‘dividend = 10’ and ‘divisor = 3’
So the division is ‘10/3 = 3.3333……’.
Return only integer part ‘3’


In test Case 2:

Given ‘dividend = -9’ and ‘divisor = 2’
So the division is ‘-9/2 = -4.5’.
Return only integer part ‘-4’
Sample Input 2:
3
7 -3
-9 -1
-1 2
Sample Output 2:
-2
 9
 0
Reset Code
Full screen
copy-code
Console