Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Tragedy of TAMA

By zobair14 · Limits 1s, 512 MB

A tangent to a circle is a line in the plane of a circle which intersects the circle in exactly one point. Two circles can have one or more than one common tangent(s).

A tangent of two circles is called a common internal tangent if the intersection of the tangent and the line segment joining the centers is not empty. For example AB and CD are common internal tangents in the picture.

A tangent of two circles is a common external tangent if the intersection of the tangent and the line segment joining the centers is empty. For example, EF and GF are common external tangents.

You are given two circles. Co-ordinates of center of one circle is (Cx1, Cy1) and its radius is R1. Co-ordinates of center of the other circle is (Cx2, Cy2) and its radius is R2.

If the circles have more than one common internal tangents, then you have to find the intersecting point of those tangents.


In the first line of input, an integer T is given, the number of test cases.
In each of the following lines, a test case is described with 6 integers: Cx1, Cy1, R1, Cx2, Cy2 and R2.

  • 1 ≤ T ≤ 100000
  • 0 ≤ Cx1, Cy1, Cx2, Cy2 ≤ 100
  • 1 ≤ R1, R2 ≤ 100


Print the co-ordinates (Px, Py) of the intersecting point of the common internal tangents.

For each test case, print the numbers Px and Py separated by a space in a single line. Print each number in a/b format, where a and b are co-prime i.e. gcd(a, b) = 1.

If a number is 0, then print only 0, no need for a/b format. If the point does not exist, just print NOT POSSIBLE in that line.

Print the answer for each test case in a separate single line. See sample I/O for example.


3 6 2 20 3 4
26/3 5/1



    87% Solution Ratio

    Mansura_170300Earliest, Aug '19

    rezaulhsagarFastest, 0.0s

    fsshakkhorLightest, 1.4 MB

    sarthakmannaShortest, 477B


    Login to submit


    Category: Geometry

    Toph uses cookies. By continuing you agree to our Cookie Policy.