Given four integers N, A, K, n where N represents the number of sides the polygon, A represents the initial angle of the polygon, K represents the per angle increase, the task is to find the nth angle of the polygon having N sides. If it is not possible then print -1.
Input: N = 3, A = 30, K = 30, n = 3
The 3rd angle of the polygon having three sides is 90 degree as the all angles are 30, 60, 90.
Input: N = 4, A = 40, K = 30, n = 3
It is not possible to create that polygon whose initial angle is 40 and no. of sides are 4.
Approach: The idea is to observe that the angles of the polygon are increasing in the terms of Arithmetic Progression by a difference of K degree.
- Find out the angular sum of the N sided polygon and the sum of the angles of the given polygon.
- Check if both the values are equal or not. If yes, then the nth angle is possible hence find the nth angle.
- Otherwise, print -1.
Below is the implementation of the above approach:
Time Complexity: O(1)
Auxiliary Space: O(1)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Check if it is possible to create a polygon with a given angle
- Angle between 3 given vertices in a n-sided regular polygon
- Number of occurrences of a given angle formed using 3 vertices of a n-sided regular polygon
- Program to find the Interior and Exterior Angle of a Regular Polygon
- Angle between a chord and a tangent when angle in the alternate segment is given
- Central angle of a N sided Regular Polygon
- Find the angle of Rotational Symmetry of an N-sided regular polygon
- Angle subtended by the chord when the angle subtended by another chord of same length is given
- Exterior angle of a cyclic quadrilateral when the opposite interior angle is given
- 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
- Program to calculate angle on circumference subtended by the chord when the central angle subtended by the chord is given
- Area of Triangle using Side-Angle-Side (length of two sides and the included angle)
- Minimum initial vertices to traverse whole matrix with given conditions
- Find total no of collisions taking place between the balls in which initial direction of each ball is given
- Find initial sequence that produces a given Array by cyclic increments upto index P
- Is it possible to reach N and M from 1 and 0 respectively as per given conditio
- Length of the chord of the circle whose radius and the angle subtended at the center by the chord is given
- Queries to increment array elements in a given range by a given value for a given number of times
- Count of elements that can be deleted without disturbing the mean of the initial array
- Minimum value to be assigned to the elements so that sum becomes greater than initial sum
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.