Given an n-sided regular polygon and an angle θ, the task is to find number of occurrences of angle ( Ai, Aj, Ak ) = θ ( i < j < k) in a regular n-gon (regular polygon with n vertices) with vertices marked as A1, A2, …, An.
Input: n = 4, ang = 90 Output: 4 Input: n = 6, ang = 50 Output: 0
- First we check whether such an angle can exist or not.
- Consider the vertices to be x, y, and z and the angle to find be ∠ xyz.
- The number of edges between x and y be a and the number of edges between y and z be b.
- Then ∠ xyz = 180 – (180*(a+b)) / n.
- Thus ∠ xyz * n (mod 180) = 0.
- Next we need to find the count of such angles.
- As the polygon is regular we just need to calculate the count of such an angle at one vertex and can directly multiply our result by n (the number of vertices).
- At each vertex the angle can be found at n-1-freq times where freq = (n*ang)/180 and depicts the number of edges remaining after creating the required angle i.e. the number of edges between z and x.
Below is the implementation of the above approach:
- Write a program to reverse digits of a number
- Write an Efficient Method to Check if a Number is Multiple of 3
- Write an Efficient C Program to Reverse Bits of a Number
- Minimum number of jumps to reach end
- Find minimum number to be divided to make a number a perfect square
- Find whether a given number is a power of 4 or not
- Print all combinations of points that can compose a given number
- Check if a number is multiple of 5 without using / and % operators
- Given a number, find the next smallest palindrome
- Count the number of possible triangles
- Select a random number from stream, with O(1) space
- Program to convert a given number to words
- Efficient program to print all prime factors of a given number
- Check if a number is Palindrome
- Random number generator in arbitrary probability distribution fashion
- How to check if a given point lies inside or outside a polygon?
- Count digits in given number N which divide N
- How to check if a given number is Fibonacci number?
- Program for nth Catalan Number
- Count trailing zeroes in factorial of a number