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++
#include <bits/stdc++.h>
using namespace std;
int countObtuseAngles(int a, int b, int k)
{
int c1 = (b - a) - 1;
int c2 = (k - b) + (a - 1);
if (c1 == c2)
return 0;
return min(c1, c2);
}
int main()
{
int k = 6, a = 1, b = 3;
cout << countObtuseAngles(a, b, k);
return 0;
}
Java
class GFG {
static int countObtuseAngles(int a,
int b, int k)
{
int c1 = (b - a) - 1;
int c2 = (k - b) + (a - 1);
if (c1 == c2)
return 0;
return min(c1, c2);
}
public static void main(String arg[])
{
int k = 6, a = 1, b = 3;
System.out.print(countObtuseAngles(a, b, k));
}
}
Python
def countObtuseAngles( a, b, k):
c1 = (b - a) - 1
c2 = (k - b) + (a - 1)
if (c1 == c2):
return 0
return min(c1, c2)
k, a, b = 6, 1, 3
print countObtuseAngles(a, b, k)
C#
PHP
<?php
function countObtuseAngles($a, $b, $k)
{
$c1 = ($b - $a) - 1;
$c2 = ($k - $b) + ($a - 1);
if ($c1 == $c2)
return 0;
return min($c1, $c2);
}
$k = 6; $a = 1; $b = 3;
echo countObtuseAngles($a, $b, $k);
?>
Javascript
<script>
function countObtuseAngles(a , b , k) {
var c1 = (b - a) - 1;
var c2 = (k - b) + (a - 1);
if (c1 == c2)
return 0;
return Math.min(c1, c2);
}
var k = 6, a = 1, b = 3;
document.write(countObtuseAngles(a, b, k));
</script>
Output :
1
Time Complexity: O(1) Auxiliary Space: O(1)
Feeling lost in the world of random DSA topics, wasting time without progress? It's time for a change! Join our DSA course, where we'll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 geeks!
Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated :
22 Jun, 2022
Like Article
Save Article
Share your thoughts in the comments
Add Your Comment
Please Login to comment...