Related Articles

# Number of cycles in a Polygon with lines from Centroid to Vertices

• Last Updated : 26 Mar, 2021

Given a number N which denotes the number of sides of the polygon where the centroid of the polygon is connected with all the vertices, the task is to find the number of cycles in the polygon.
Examples:

Input: N = 4
Output: 13
Input: N = 8
Output: 57

Approach: This problem follows a simplistic approach where we can use a simple formula to find the number of cycles in Polygon with lines from Centroid to Vertices. To deduce the number of cycles we can use this formula:

(N) * (N – 1) + 1

If the value of N is 4, we can use this simple formula to find the number of Cycles which is 13. In a similar manner, if the value of N is 10, then the number of Cycles would be 91.
Below is the implementation of the above approach:

## C++

 `// C++ program to find number``// of cycles in a Polygon with``// lines from Centroid to Vertices` `#include ``using` `namespace` `std;` `// Function to find the Number of Cycles``int` `nCycle(``int` `N)``{``    ``return` `(N) * (N - 1) + 1;``}` `// Driver code``int` `main()``{``    ``int` `N = 4;``    ``cout << nCycle(N)``         ``<< endl;``    ``return` `0;``}`

## Java

 `// Java program to find number``// of cycles in a Polygon with``// lines from Centroid to Vertices``class` `GFG{`` ` `// Function to find the Number of Cycles``static` `int` `nCycle(``int` `N)``{``    ``return` `(N) * (N - ``1``) + ``1``;``}`` ` `// Driver code``public` `static` `void` `main (String[] args)``{``    ``int` `N = ``4``;``    ``System.out.println(nCycle(N));``}``}` `// This code is contributed by rock_cool`

## Python3

 `# Python3 program to find number``# of cycles in a Polygon with``# lines from Centroid to Vertices` `# Function to find the Number of Cycles``def` `nCycle(N):``    ` `    ``return` `(N) ``*` `(N ``-` `1``) ``+` `1` `# Driver code``N ``=` `4``print``(nCycle(N))` `# This code is contributed by divyeshrabadiya07`

## C#

 `// C# program to find number``// of cycles in a Polygon with``// lines from Centroid to Vertices``using` `System;``class` `GFG{` `// Function to find the Number of Cycles``static` `int` `nCycle(``int` `N)``{``    ``return` `(N) * (N - 1) + 1;``}` `// Driver code``public` `static` `void` `Main (String[] args)``{``    ``int` `N = 4;``    ``Console.Write(nCycle(N));``}``}` `// This code is contributed by shivanisinghss2110`

## Javascript

 ``
Output:
`13`

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.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

In case you wish to attend live classes with experts, please refer DSA Live Classes for Working Professionals and Competitive Programming Live for Students.

My Personal Notes arrow_drop_up