Check if a Number is Pentacontagon

By | December 1, 2024

Given an integer N, the task is to check if it is a pentacontagon number or not.

Pentacontagon number is class of figurate number. It has 50 – sided polygon called pentacontagon. The N-th pentacontagon number count’s the 50 number of dots and all others dots are surrounding with a common sharing corner and make a pattern. The first few pentacontagonol numbers are 1, 50, 147, 292 ….

Examples:

Input: N = 50
Output: Yes
Explanation:
Second pentacontagon number is 50.

Input: 35
Output: No

Approach:
The Kth term of the pentacontagon number is given as K^{th} Term = (48*K^{2} – 46*K)/2
As we have to check that the given number can be expressed as a pentacontagon number or not. This can be checked as follows –

Finally, check the value of computed using this formulae is an integer, which means that N is a pentacontagon number.

Below is the implementation of the above approach:

// C++ implementation to check whether
// a number is a pentacontagon number or not

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

// Function to check whether the
// number is a pentacontagon number
bool is_pentacontagon(int N)
{
    float n = (66 + sqrt(384 * N + 2116)) / 96;

    // Condition to check if the
    // number is a pentacontagon number
    return (n - (int)n) == 0;
}

// Driver Code
int main()
{
    int i = 50;

    // Function call
    if (is_pentacontagon(i)) {
        cout << "Yes";
    } else {
        cout << "No";
    }

    return 0;
}

Output:

Yes
Author: Mithlesh Upadhyay

Mithlesh Upadhyay is a Computer Science and AI expert from Madhya Pradesh with strong academic background (BE in CSE and M.Tech in AI) and over six years of experience in technical content development. He has contributed tech articles, led teams, and worked in Full Stack Development and Data Science. He founded the w3colleges.org portal for learning resources.