![]() |
VOOZH | about |
Given two integers r and R representing the length of Inradius and Circumradius respectively, the task is to calculate the distance d between Incenter and Circumcenter.
Inradius The inradius( r ) of a regular triangle( ABC ) is the radius of the incircle (having center as l), which is the largest circle that will fit inside the triangle.
Circumradius: The circumradius( R ) of a triangle is the radius of the circumscribed circle (having center as O) of that triangle.
Examples:
Input: r = 2, R = 5
Output: 2.24Input: r = 5, R = 12
Output: 4.9
Approach:
The problem can be solved using Euler's Theorem in geometry, which states that the distance between the incenter and circumcenter of a triangle can be calculated by the equation:
Below is the implementation of the above approach:
2.24
Time Complexity: O(logn) since time complexity of sqrt is O(logn)
Auxiliary Space: O(1)