📜  程序检查N是否为同位四边形数字

📅  最后修改于: 2021-05-06 10:00:14             🧑  作者: Mango

给定一个整数N ,任务是检查它是否是二十位三角形。

例子:

方法:

  1. 二十位四边形数的第K项为
    K^{th} Term = \frac{22*K^{2} - 20*K}{2}
  2. 因为我们必须检查给定的数字是否可以表示为二十位三角形。可以检查如下–
  1. 最后,检查使用此公式计算的值是一个整数,这意味着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