Open In App

Count of obtuse angles in a circle with ‘k’ equidistant points between 2 given points

Last Updated : 22 Jun, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

A circle is given with k equidistant points on its circumference. 2 points A and B are given in the circle. Find the count of all obtuse angles (angles larger than 90 degree) formed from /_ACB, where C can be any point in circle other than A or B. 
Note : 
A and B are not equal. 
A < B. 
Points are between 1 and K(both inclusive).
 

Examples : 
 

Input : K = 6, A = 1, B = 3.
Output : 1
Explanation : In the circle with 6 
equidistant points, when C = 2 i.e. 
/_123, we get obtuse angle.

Input : K = 6, A = 1, B = 4.
Output : 0
Explanation : In this circle, there 
is no such C that form an obtuse angle.

 

It can be observed that if A and B have equal elements in between them, there can’t be any C such that ACB is obtuse. Also, the number of possible obtuse angles are the smaller arc between A and B.
Below is the implementation : 
 

C++




// C++ program to count number of obtuse
// angles for given two points.
#include <bits/stdc++.h>
using namespace std;
 
int countObtuseAngles(int a, int b, int k)
{
    // There are two arcs connecting a
    // and b. Let us count points on
    // both arcs.
    int c1 = (b - a) - 1;
    int c2 = (k - b) + (a - 1);
 
    // Both arcs have same number of
    // points
    if (c1 == c2)
        return 0;
 
    // Points on smaller arc is answer
    return min(c1, c2);
}
 
// Driver code
int main()
{
    int k = 6, a = 1, b = 3;
    cout << countObtuseAngles(a, b, k);
    return 0;
}


Java




// Java program to count number of obtuse
// angles for given two points
class GFG {
 
    static int countObtuseAngles(int a,
                                 int b, int k)
    {
 
        // There are two arcs connecting a
        // and b. Let us count points on
        // both arcs.
        int c1 = (b - a) - 1;
        int c2 = (k - b) + (a - 1);
 
        // Both arcs have same number of
        // points
        if (c1 == c2)
            return 0;
 
        // Points on smaller arc is answer
        return min(c1, c2);
    }
 
    // Driver Program to test above function
    public static void main(String arg[])
    {
 
        int k = 6, a = 1, b = 3;
        System.out.print(countObtuseAngles(a, b, k));
    }
}
 
// This code is contributed by Anant Agarwal.


Python




# C++ program to count number of obtuse
# angles for given two points.
 
def countObtuseAngles( a, b, k):
    # There are two arcs connecting a
    # and b. Let us count points on
    # both arcs.
    c1 = (b - a) - 1
    c2 = (k - b) + (a - 1)
  
    # Both arcs have same number of
    # points
    if (c1 == c2):
       return 0
      
    # Points on smaller arc is answer
    return min(c1, c2)
  
# Driver code
k, a, b = 6, 1, 3
print countObtuseAngles(a, b, k)
 
# This code is contributed by Sachin Bisht


C#





PHP




<?php
// PHP program to count number
// of obtuse angles for given
// two points.
 
function countObtuseAngles($a, $b, $k)
{
    // There are two arcs connecting a
    // and b. Let us count points on
    // both arcs.
    $c1 = ($b - $a) - 1;
    $c2 = ($k - $b) + ($a - 1);
 
    // Both arcs have same number of
    // points
    if ($c1 == $c2)
        return 0;
 
    // Points on smaller arc is answer
    return min($c1, $c2);
}
 
// Driver code
$k = 6; $a = 1; $b = 3;
echo countObtuseAngles($a, $b, $k);
 
// This code is contributed by aj_36
?>


Javascript




<script>
 
// Javascript program to count number of obtuse
// angles for given two points   
function countObtuseAngles(a , b , k) {
 
        // There are two arcs connecting a
        // and b. Let us count points on
        // both arcs.
        var c1 = (b - a) - 1;
        var c2 = (k - b) + (a - 1);
 
        // Both arcs have same number of
        // points
        if (c1 == c2)
            return 0;
 
        // Points on smaller arc is answer
        return Math.min(c1, c2);
    }
 
    // Driver Program to test above function
 
        var k = 6, a = 1, b = 3;
        document.write(countObtuseAngles(a, b, k));
 
// This code is contributed by todaysgaurav
 
</script>


Output : 

1

Time Complexity: O(1) 
Auxiliary Space: O(1)

 



Similar Reads

Count of acute, obtuse and right triangles with given sides
Given an array of n positive distinct integers representing lengths of lines that can form a triangle. The task is to find the number of acute triangles, obtuse triangles, and right triangles separately that can be formed from the given array. Examples: Input : arr[] = { 2, 3, 9, 10, 12, 15 }. Output : Acute Triangle: 2 Right Triangle: 1 Obtuse Tri
13 min read
Number of cells in matrix which are equidistant from given two points
Given a matrix of N rows and M columns, given two points on the matrix; the task is to count the number of cells that are equidistant from given two points. Any traversal either in the horizontal direction or vertical direction or both ways is considered valid but the diagonal path is not valid.Examples: Input: 5 5 2 4 5 3 Output: 5 Explanation: Ou
5 min read
Equation of circle when three points on the circle are given
Given three coordinates that lie on a circle, (x1, y1), (x2, y2), and (x3, y3). The task is to find the equation of the circle and then print the centre and the radius of the circle. The equation of circle in general form is x² + y² + 2gx + 2fy + c = 0 and in radius form is (x - h)² + (y -k)² = r², where (h, k) is the centre of the circle and r is
11 min read
Total number of triplets (A, B, C) in which the points B and C are Equidistant to A
Given an array arr containing N points, the task is to find the total number of triplets in which the points are equidistant. A triplet of points (P1, P2, P3) is said to be equidistant when the distance between P1 and P2 is the same as of the distance between P1 and P3. Note: The order of the points matters, i.e., (P1, P2, P3) is different from (P2
7 min read
Program to find smallest difference of angles of two parts of a given circle
Given a division of a circle into n pieces as an array of size n. The ith element of the array denotes the angle of one piece. Our task is to make two continuous parts from these pieces so that the difference between angles of these two parts is minimum.Examples : Input : arr[] = {90, 90, 90, 90} Output : 0 In this example, we can take 1 and 2 piec
6 min read
Count of triplets from the given string with non-equidistant characters
Given a string s containing letters 'a', 'b' and 'c', the task is to calculate all possible triplets made up of the three characters, and the distance between them should not be the same. Distance between two letters is basically the difference between their indices. Examples: Input: s = "aabc" Output: 1 Explanation: Two possible triplets comprisin
6 min read
Count non-equidistant triplets of distinct array elements having indices in increasing order
Given an array arr[] of size N consisting of only 0s, 1s and 2s, the task is to find the count of triplets of indices (i, j, k) containing distinct array elements such that i &lt; j &lt; k and the array elements are not equidistant, i.e, (j - i )!= (k - j). Examples: Input: arr[] = { 0, 1, 2, 1 } Output:1 Explanation: Only triplet (0, 2, 3) contain
10 min read
Count ways to remove objects such that exactly M equidistant objects remain
Given an integer N, representing objects placed adjacent to each other, the task is to count the number of ways to remove objects such that after their removal, exactly M objects are left and the distance between each adjacent object is equal. Examples: Input: N = 5, M = 3Output: 4Explanation:Let the initial arrangement be A1 A2 A3 A4 A5.The follow
6 min read
Check whether it is possible to join two points given on circle such that distance between them is k
Given two circles and a length, K. Find whether we can join two points (one on perimeter of each circle), so that distance between the points is K. (Coordinates of both points need not be an integer value). Examples: Input: Circle-1 Center (0, 0) Radius = 5 Circle-2 Center (8, 3) Radius = 2 K = 3 Output: Yes Maximum Distance: 15 Minimum Distance: 2
10 min read
Angle subtended by the chord to center of the circle when the angle subtended by the another equal chord of a congruent circle is given
Given are two congruent circles with two equal chords. The angle subtended to the center from the chord of one of the circles is given. The task is to find the angle subtended by the chord to the center of another circle.Examples: Input: z = 48 Output: 48 degrees Input: z = 93 Output: 93 degrees Approach: In triangle AOB and PXQ AO = PX(radii of co
3 min read
Article Tags :
Practice Tags :