Program to check if N is a Tetradecagonal Number
Last Updated :
01 Dec, 2022
Given an integer N, the task is to check if N is a Tetradecagonal Number or not. If the number N is a Tetradecagonal Number then print “Yes” else print “No”.
Tetradecagonal Number is 14-sided polygon called Tetrakaidecagon or Tetradecagon and belongs to the figurative number. The nth tetradecagonal number dotted with some dots and create a series of the pattern. They have a common sharing corner point and dotted with their spaces to each other. The dots continue with nth nested loop.The first few Tetradecagonal Numbers are 1, 14, 39, 76, 125, 186, …
Examples:
Input: N = 14
Output: Yes
Explanation:
Second tetradecagonal number is 14.
Input: N = 40
Output: No
Approach:
- The Kth term of the tetradecagonal number is given as
- As we have to check whether the given number can be expressed as a Tetradecagonal Number or not. This can be checked as:
=>
=>
- If the value of K calculated using the above formula is an integer, then N is a Tetradecagonal Number.
- Else N is not a Tetradecagonal Number.
Below is the implementation of the above approach:
C++
#include <bits/stdc++.h>
using namespace std;
bool istetradecagonal( int N)
{
float n
= (10 + sqrt (96 * N + 100))
/ 24;
return (n - ( int )n) == 0;
}
int main()
{
int N = 11;
if (istetradecagonal(N)) {
cout << "Yes" ;
}
else {
cout << "No" ;
}
return 0;
}
|
Java
import java.lang.Math;
class GFG{
public static boolean istetradecagonal( int N)
{
double n = ( 10 + Math.sqrt( 96 * N +
100 )) / 24 ;
return (n - ( int )n) == 0 ;
}
public static void main(String[] args)
{
int N = 11 ;
if (istetradecagonal(N))
{
System.out.println( "Yes" );
}
else
{
System.out.println( "No" );
}
}
}
|
Python3
import math
def istetradecagonal(N):
n = ( 10 + math.sqrt( 96 * N + 100 )) / 24
if (n - int (n)) = = 0 :
return True
return False
N = 11
if (istetradecagonal(N)):
print ( "Yes" )
else :
print ( "No" )
|
C#
using System;
class GFG{
public static bool istetradecagonal( int N)
{
double n = (10 + Math.Sqrt(96 * N +
100)) / 24;
return (n - ( int )n) == 0;
}
static public void Main ()
{
int N = 11;
if (istetradecagonal(N))
{
Console.Write( "Yes" );
}
else
{
Console.Write( "No" );
}
}
}
|
Javascript
<script>
function istetradecagonal(N)
{
n = (10 + Math.sqrt(96 * N + 100))
/ 24;
return (n - parseInt(n)) == 0;
}
N = 11;
if (istetradecagonal(N)) {
document.write( "Yes" );
}
else {
document.write( "No" );
}
</script>
|
Time Complexity: O(log N) because sqrt() function is being used
Auxiliary Space: O(1)
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...