给定一个整数N ,任务是检查它是否是二十位三角形。
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, …
例子:
Input: N = 24
Output: Yes
Explanation:
Second icositetragonal number is 24.
Input: N = 30
Output: No
方法:
- 二十位四边形数的第K个项为
- 因为我们必须检查给定的数字是否可以表示为二十位三角形。可以检查如下–
=>
=>
- 最后,检查使用此公式计算的值是一个整数,这意味着N是一个二十四方晶数。
下面是上述方法的实现:
C++
// C++ implementation to check that
// a number is icositetragonal number or not
#include
using namespace std;
// Function to check that the
// number is a icositetragonal number
bool isicositetragonal(int N)
{
float n
= (10 + sqrt(44 * N + 100))
/ 22;
// Condition to check if the
// number is a icositetragonal number
return (n - (int)n) == 0;
}
// Driver Code
int main()
{
int i = 24;
// Function call
if (isicositetragonal(i)) {
cout << "Yes";
}
else {
cout << "No";
}
return 0;
}
Java
// Java implementation to check that
// a number is icositetragonal number or not
class GFG{
// Function to check that the
// number is a icositetragonal number
static boolean isicositetragonal(int N)
{
float n = (float)((10 + Math.sqrt(44 * N +
100)) / 22);
// Condition to check if the
// number is a icositetragonal number
return (n - (int)n) == 0;
}
// Driver Code
public static void main(String[] args)
{
int i = 24;
// Function call
if (isicositetragonal(i))
{
System.out.print("Yes");
}
else
{
System.out.print("No");
}
}
}
// This code is contributed by 29AjayKumar
Python3
# Python3 implementation to check that
# a number is icositetragonal number
# or not
import math
# Function to check that the number
# is a icositetragonal number
def isicositetragonal(N):
n = (10 + math.sqrt(44 * N + 100)) / 22
# Condition to check if the number
# is a icositetragonal number
return (n - int(n)) == 0
# Driver Code
i = 24
# Function call
if (isicositetragonal(i)):
print("Yes")
else:
print("No")
# This code is contributed by divyamohan123
C#
// C# implementation to check that
// a number is icositetragonal number or not
using System;
class GFG{
// Function to check that the
// number is a icositetragonal number
static bool isicositetragonal(int N)
{
float n = (float)((10 + Math.Sqrt(44 * N +
100)) / 22);
// Condition to check if the
// number is a icositetragonal number
return (n - (int)n) == 0;
}
// Driver Code
public static void Main()
{
int i = 24;
// Function call
if (isicositetragonal(i))
{
Console.Write("Yes");
}
else
{
Console.Write("No");
}
}
}
// This code is contributed by Akanksha_Rai
Javascript
输出:
Yes