Number of cycles

You are given an N-sided regular polygon. You have connected the center of the polygon with all the vertices, thus dividing the polygon into N equal parts.

Your task is to find the count of simple cycles that exist in the modified structure of the polygon.

Example:

Input:  n = 4
Output: 13

Approach

C++

#include <bits/stdc++.h>
using namespace std;

int numbOfCycles(int n)
{
    long long ans = n * (n - 1) + 1;
    return ans;
}
int main()
{
    long long n = 4;

    cout << numbOfCycles(n<< "\n";
    return 0;
}


No comments:

Post a Comment