Program to check if N is a Icositetragonal number
Last Updated :
30 Nov, 2022
Given an integer N, the task is to check if it is a icositetragonal number or not.
icositetragonal number:
s a class of figurate number. It has a 24-sided polygon called Icositetragon. The N-th Icositetragonal number count’s the number of dots and all others dots are surrounding with a common sharing corner and make a pattern
The first few icositetragonal numbers are 1, 24, 69, 136, 225, 336, …
Examples:
Input: N = 24
Output: Yes
Explanation:
Second icositetragonal number is 24.
Input: N = 30
Output: No
Approach:
1. The Kth term of the icositetragonal number is given as
2. As we have to check that the given number can be expressed as a icositetragonal number or not. This can be checked as follows –
=>
=>
3. Finally, check the value computed using this formula is an integer, which means that N is a icositetragonal number.
Below is the implementation of the above approach:
C++
#include <bits/stdc++.h>
using namespace std;
bool isicositetragonal( int N)
{
float n
= (10 + sqrt (44 * N + 100))
/ 22;
return (n - ( int )n) == 0;
}
int main()
{
int i = 24;
if (isicositetragonal(i)) {
cout << "Yes" ;
}
else {
cout << "No" ;
}
return 0;
}
|
Java
class GFG{
static boolean isicositetragonal( int N)
{
float n = ( float )(( 10 + Math.sqrt( 44 * N +
100 )) / 22 );
return (n - ( int )n) == 0 ;
}
public static void main(String[] args)
{
int i = 24 ;
if (isicositetragonal(i))
{
System.out.print( "Yes" );
}
else
{
System.out.print( "No" );
}
}
}
|
Python3
import math
def isicositetragonal(N):
n = ( 10 + math.sqrt( 44 * N + 100 )) / 22
return (n - int (n)) = = 0
i = 24
if (isicositetragonal(i)):
print ( "Yes" )
else :
print ( "No" )
|
C#
using System;
class GFG{
static bool isicositetragonal( int N)
{
float n = ( float )((10 + Math.Sqrt(44 * N +
100)) / 22);
return (n - ( int )n) == 0;
}
public static void Main()
{
int i = 24;
if (isicositetragonal(i))
{
Console.Write( "Yes" );
}
else
{
Console.Write( "No" );
}
}
}
|
Javascript
<script>
function isicositetragonal(N)
{
var n = (10 + Math.sqrt(44 * N + 100))
/ 22;
return (n - parseInt(n)) == 0;
}
var i = 24;
if (isicositetragonal(i)) {
document.write( "Yes" );
}
else {
document.write( "No" );
}
</script>
|
Time Complexity: O(log N), it is time taken by inbuilt sqrt() function
Auxiliary Space: O(1)
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...