Division

Problem #6

Tags: computing instructional

Who solved this?

Previous:Multiplication Next:Compound Interest


Division is the inverse to multiplication, such that if a * b = c, then c / a = b. In this case c would be called the dividend, a would be the divisor, and b would be the quotient.

To calculate a quotient, we first draw a symbol called a division bracket, placing the dividend c to the right, and the divisor a to the left, and leaving a space for the quotient above. Regarding the decimal point, count the quantity of digits after the decimal point in the divisor, then shift the decimal in the dividend to the right by that quantity of digits.

  1. Starting witht he leftmost digit of c, take as many digits as necessary to form the number d, such that d > a.
  2. Determine the largest possible digit which could be multiplied to a to yield a product less than d. Write that digit as the next digit in the quotient and write that product below.
  3. Take the difference between d that product to yield a new value for d.
  4. Append the next digit of c to d. If d is still less than a, append another digit and write a 0 as the next digit in the quotient.

Then count the total quantity of decimal places present to the left of the decimal point for both the dividend and the divisor, and place the decimal point in the quotient after that quantity of digits.

Here is an example, dividing 1.2 by 3.4. Only the first six digits are calculated.

   00352941  =>  0.352941
   ________
34)12000000
  - 102
  -----
     180
   - 170
   -----
      100
    -  68
    -----
       320
     - 306
     -----
        140
      - 136
      -----
         40
       - 34
       ----
          6

Problem Statement

You will be given several pairs of numbers. Divide one into the other and return the quotient.

Input Data
First line will be Q, the quantity of testcases.
Q lines will then follow, each with two space-separated values in the format c a being the dividend and divisor respectively.

Answer
Should consist of Q values, being the quotient of each given testcase.
Round each answer to 50 digits after the decimal point.
Remove all trailing zeroes.

Example

input data:
2
67 5
131 107

answer:
13.4 1.22429906542056074766355140186915887850467289719626
You need to login to get test data and submit solution.