Given an integer N, the task is to check if it is a enneacontagon number or not.
enneacontagon number: is class of figurate number. It has 90 – sided polygon called enneacontagon. The N-th enneacontagon number count’s the 90 number of dots and all others dots are surrounding with a common sharing corner and make a pattern. The first few enneacontagonol numbers are 1, 90, 267, 532 …
Examples :
Input : N = 90 Output : Yes Explanation : Second enneacontagon number is 90. Input : 35 Output : No
Approach :
- The Kth term of the enneacontagon number is given as Kth Term = (88*K2 – 86*K) / 2
- As we have to check that the given number can be expressed as a enneacontagon number or not. This can be checked as follows –
N = (88*K2 - 86*K) / 2, so K = (86 + sqrt(704*N + 7396)) / 176
- Finally, check the value of computed using this formulae is an integer, which means that N is a enneacontagon number.
Implementation :
// C++ implementation to check that
// a number is a enneacontagon number or not
#include <bits/stdc++.h>
using namespace std;
// Function to check that the
// number is a enneacontagon number
bool isEnneacontagon(int N)
{
float n
= (86 + sqrt(704*N + 7396))
/ 176;
// Condition to check if the
// number is a enneacontagon number
return (n - (int)n) == 0;
}
// Driver Code
int main()
{
int i = 90;
// Function call
if (isEnneacontagon(i)) {
cout << "Yes";
}
else {
cout << "No";
}
return 0;
}