Skip to content
Related Articles

Related Articles

Number of cycles in a Polygon with lines from Centroid to Vertices
  • Last Updated : 02 Aug, 2020

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

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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;
}

chevron_right


Java

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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

chevron_right


C#

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


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.

My Personal Notes arrow_drop_up
Recommended Articles
Page :