📜  二十三方数

📅  最后修改于: 2021-10-23 08:30:57             🧑  作者: Mango

给定一个数字N ,任务是找到NIcositrigonal 数字或不。

例子:

方法:第 N 个 Icositrigonal 数由以下公式给出:

Tn = (21n^2 - 19n)/2

下面是上述方法的实现:

C++
// C++ program to find nth
// Icositrigonal number
 
#include 
using namespace std;
 
// Function to find N-th
// Icositrigonal number
int Icositrigonal_num(int n)
{
    // Formula to calculate nth
    // Icositrigonal number
    return (21 * n * n - 19 * n) / 2;
}
 
// Driver Code
int main()
{
    int n = 3;
    cout << Icositrigonal_num(n) << endl;
     
    n = 10;
    cout << Icositrigonal_num(n);
 
    return 0;
}


Java
// Java program to find nth
// Icositrigonal number
class GFG{
 
// Function to find N-th
// Icositrigonal number   
static int IcositrigonalNum(int n)
{
     
    // Formula to calculate nth
    // Icositrigonal number
    return (21 * n * n - 19 * n) / 2;
}
 
// Driver code
public static void main(String[] args)
{
    int n = 3;
    System.out.print(IcositrigonalNum(n) + "\n");
     
    n = 10;
    System.out.print(IcositrigonalNum(n));
}
}
 
// This code is contributed by spp____


Python3
# Python3 program to find nth
# Icositrigonal number
 
# Function to find N-th
# Icositrigonal number
def IcositrigonalNum(n):
     
    # Formula to calculate nth
    # Icositrigonal number
    return (21 * n * n - 19 * n) / 2;
 
# Driver code
n = 3
print(IcositrigonalNum(n))
 
n = 10
print(IcositrigonalNum(n))
 
# This code is contributed by spp____


C#
// C# program to find nth
// Icositrigonal number
using System;
 
class GFG{
 
// Function to find N-th
// Icositrigonal number    
static int IcositrigonalNum(int n)
{
     
    // Formula to calculate nth
    // Icositrigonal number
    return (21 * n * n - 19 * n) / 2;
}
 
// Driver code
public static void Main()
{
    int n = 3;
    Console.WriteLine(IcositrigonalNum(n));
     
    n = 10;
    Console.WriteLine(IcositrigonalNum(n));
}
}
 
// This code is contributed by spp____


Javascript


输出:
66
955

参考: https : //en.wikipedia.org/wiki/Polygonal_number

如果您希望与专家一起参加现场课程,请参阅DSA 现场工作专业课程学生竞争性编程现场课程