Check if a Number is Triacontakaidigon

By | December 1, 2024

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

Triacontakaidigon number is class of figurate number. It has 32 – sided polygon called Triacontakaidigon. The N-th triacontakaidigon number count’s the 32 number of dots and all others dots are surrounding with a common sharing corner and make a pattern. The first few triacontakaidigonol numbers are 1, 32, 93, 184 ….

Examples:

Input: N = 32
Output: Yes
Explanation:
Second triacontakaidigon number is 32.

Input: 35
Output: No

Approach:
The Kth term of the triacontakaidigon number is given as K^{th} Term = (30*K^{2} – 28*K)/2
As we have to check that the given number can be expressed as a triacontakaidigon 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 triacontakaidigon number.

Below is the implementation of the above approach:

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

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

// Function to check whether the
// number is a triacontakaidigon number
bool is_triacontakaidigon(int N)
{
    float n = (28 + sqrt(240 * N + 784)) / 60;

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

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

    // Function call
    if (is_triacontakaidigon(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.