Given an n-sided regular polygon and an angle θ, the task is to find number of occurrences of angle ( A_{i}, A_{j}, A_{k} ) = θ ( i < j < k) in a regular n-gon (regular polygon with n vertices) with vertices marked as A_{1}, A_{2}, …, A_{n}.

**Examples:**

Input:n = 4, ang = 90Output:4Input:n = 6, ang = 50Output:0

**Approach:**

- 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:

`// C++ implementation of the approach ` ` ` `#include <bits/stdc++.h> ` `using` `namespace` `std; `
` ` `// Function that calculates occurrences ` `// of given angle that can be created ` `// using any 3 sides ` `int` `solve(` `int` `ang, ` `int` `n) `
`{ ` ` ` ` ` `// Maximum angle in a regular n-gon `
` ` `// is equal to the interior angle `
` ` `// If the given angle `
` ` `// is greater than the interior angle `
` ` `// then the given angle cannot be created `
` ` `if` `((ang * n) > (180 * (n - 2))) { `
` ` `return` `0; `
` ` `} `
` ` ` ` `// The given angle times n should be divisible `
` ` `// by 180 else it cannot be created `
` ` `else` `if` `((ang * n) % 180 != 0) { `
` ` `return` `0; `
` ` `} `
` ` ` ` `// Initialise answer `
` ` `int` `ans = 1; `
` ` ` ` `// Calculate the frequency `
` ` `// of given angle for each vertex `
` ` `int` `freq = (ang * n) / 180; `
` ` ` ` `// Multiply answer by frequency. `
` ` `ans = ans * (n - 1 - freq); `
` ` ` ` `// Multiply answer by the number of vertices. `
` ` `ans = ans * n; `
` ` ` ` `return` `ans; `
`} ` ` ` `// Driver code ` `int` `main() `
`{ ` ` ` `int` `ang = 90, n = 4; `
` ` ` ` `cout << solve(ang, n); `
` ` ` ` `return` `0; `
`} ` |

*chevron_right*

*filter_none*

`// Java implementation of the approach ` `class` `GFG `
`{ ` ` ` `// Function that calculates occurrences ` `// of given angle that can be created ` `// using any 3 sides ` `static` `int` `solve(` `int` `ang, ` `int` `n) `
`{ ` ` ` ` ` `// Maximum angle in a regular n-gon `
` ` `// is equal to the interior angle `
` ` `// If the given angle `
` ` `// is greater than the interior angle `
` ` `// then the given angle cannot be created `
` ` `if` `((ang * n) > (` `180` `* (n - ` `2` `))) `
` ` `{ `
` ` `return` `0` `; `
` ` `} `
` ` ` ` `// The given angle times n should be divisible `
` ` `// by 180 else it cannot be created `
` ` `else` `if` `((ang * n) % ` `180` `!= ` `0` `) `
` ` `{ `
` ` `return` `0` `; `
` ` `} `
` ` ` ` `// Initialise answer `
` ` `int` `ans = ` `1` `; `
` ` ` ` `// Calculate the frequency `
` ` `// of given angle for each vertex `
` ` `int` `freq = (ang * n) / ` `180` `; `
` ` ` ` `// Multiply answer by frequency. `
` ` `ans = ans * (n - ` `1` `- freq); `
` ` ` ` `// Multiply answer by the number of vertices. `
` ` `ans = ans * n; `
` ` ` ` `return` `ans; `
`} ` ` ` `// Driver code ` `public` `static` `void` `main (String[] args) `
`{ ` ` ` `int` `ang = ` `90` `, n = ` `4` `; `
` ` `System.out.println(solve(ang, n)); `
`} ` `} ` ` ` `// This code is contributed by Rajput-Ji ` |

*chevron_right*

*filter_none*

`# Python3 implementation of the approach ` ` ` `# Function that calculates occurrences ` `# of given angle that can be created ` `# using any 3 sides ` `def` `solve(ang, n): `
` ` ` ` `# Maximum angle in a regular n-gon `
` ` `# is equal to the interior angle `
` ` `# If the given angle `
` ` `# is greater than the interior angle `
` ` `# then the given angle cannot be created `
` ` `if` `((ang ` `*` `n) > (` `180` `*` `(n ` `-` `2` `))): `
` ` `return` `0`
` ` ` ` `# The given angle times n should be divisible `
` ` `# by 180 else it cannot be created `
` ` `elif` `((ang ` `*` `n) ` `%` `180` `!` `=` `0` `): `
` ` `return` `0`
` ` ` ` `# Initialise answer `
` ` `ans ` `=` `1`
` ` ` ` `# Calculate the frequency `
` ` `# of given angle for each vertex `
` ` `freq ` `=` `(ang ` `*` `n) ` `/` `/` `180`
` ` ` ` `# Multiply answer by frequency. `
` ` `ans ` `=` `ans ` `*` `(n ` `-` `1` `-` `freq) `
` ` ` ` `# Multiply answer by the number of vertices. `
` ` `ans ` `=` `ans ` `*` `n `
` ` ` ` `return` `ans `
` ` `# Driver code ` `ang ` `=` `90`
`n ` `=` `4`
` ` `print` `(solve(ang, n)) `
` ` `# This code is contributed by Mohit Kumar ` |

*chevron_right*

*filter_none*

`// C# implementation of the approach ` `using` `System; `
` ` `class` `GFG `
`{ ` ` ` `// Function that calculates occurrences ` `// of given angle that can be created ` `// using any 3 sides ` `static` `int` `solve(` `int` `ang, ` `int` `n) `
`{ ` ` ` ` ` `// Maximum angle in a regular n-gon `
` ` `// is equal to the interior angle `
` ` `// If the given angle `
` ` `// is greater than the interior angle `
` ` `// then the given angle cannot be created `
` ` `if` `((ang * n) > (180 * (n - 2))) `
` ` `{ `
` ` `return` `0; `
` ` `} `
` ` ` ` `// The given angle times n should be divisible `
` ` `// by 180 else it cannot be created `
` ` `else` `if` `((ang * n) % 180 != 0) `
` ` `{ `
` ` `return` `0; `
` ` `} `
` ` ` ` `// Initialise answer `
` ` `int` `ans = 1; `
` ` ` ` `// Calculate the frequency `
` ` `// of given angle for each vertex `
` ` `int` `freq = (ang * n) / 180; `
` ` ` ` `// Multiply answer by frequency. `
` ` `ans = ans * (n - 1 - freq); `
` ` ` ` `// Multiply answer by the `
` ` `// number of vertices. `
` ` `ans = ans * n; `
` ` ` ` `return` `ans; `
`} ` ` ` `// Driver code ` `public` `static` `void` `Main (String[] args) `
`{ ` ` ` `int` `ang = 90, n = 4; `
` ` `Console.WriteLine(solve(ang, n)); `
`} ` `} ` ` ` `// This code is contributed by Princi Singh ` |

*chevron_right*

*filter_none*

**Output:**

4

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.

## Recommended Posts:

- Nth angle of a Polygon whose initial angle and per angle increment is given
- Angle between 3 given vertices in a n-sided regular polygon
- Program to find the Interior and Exterior Angle of a Regular Polygon
- Central angle of a N sided Regular Polygon
- Find the angle of Rotational Symmetry of an N-sided regular polygon
- Number of triangles formed by joining vertices of n-sided polygon with one side common
- Number of triangles formed by joining vertices of n-sided polygon with two common sides and no common sides
- Number of cycles formed by joining vertices of n sided polygon at the center
- Polygon with maximum sides that can be inscribed in an N-sided regular polygon
- Area of Triangle using Side-Angle-Side (length of two sides and the included angle)
- 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 between a chord and a tangent when angle in the alternate segment 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
- Find the remaining vertices of a square from two given vertices
- Check if it is possible to create a polygon with a given angle
- Number of ways a convex polygon of n+2 sides can split into triangles by connecting vertices
- Number of cycles in a Polygon with lines from Centroid to Vertices
- Check if given polygon is a convex polygon or not

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. 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.