Open In App

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

Improve
Improve
Like Article
Like
Save
Share
Report

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 <bits/stdc++.h>
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




<script>
 
    // Javascript program to find number
    // of cycles in a Polygon with
    // lines from Centroid to Vertices
     
    // Function to find the Number of Cycles
    function nCycle(N)
    {
        return (N) * (N - 1) + 1;
    }
     
    let N = 4;
    document.write(nCycle(N));
 
</script>


Output:

13

Time Complexity: O(1) 
Auxiliary Space: O(1)



Last Updated : 26 Mar, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads