Number of cycles in a Polygon with lines from Centroid to Vertices
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++
#include <bits/stdc++.h>
using namespace std;
int nCycle( int N)
{
return (N) * (N - 1) + 1;
}
int main()
{
int N = 4;
cout << nCycle(N)
<< endl;
return 0;
}
|
Java
class GFG{
static int nCycle( int N)
{
return (N) * (N - 1 ) + 1 ;
}
public static void main (String[] args)
{
int N = 4 ;
System.out.println(nCycle(N));
}
}
|
Python3
def nCycle(N):
return (N) * (N - 1 ) + 1
N = 4
print (nCycle(N))
|
C#
using System;
class GFG{
static int nCycle( int N)
{
return (N) * (N - 1) + 1;
}
public static void Main (String[] args)
{
int N = 4;
Console.Write(nCycle(N));
}
}
|
Javascript
<script>
function nCycle(N)
{
return (N) * (N - 1) + 1;
}
let N = 4;
document.write(nCycle(N));
</script>
|
Time Complexity: O(1)
Auxiliary Space: O(1)
Last Updated :
26 Mar, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...