📜  十二进制数

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

给定一个数 n,任务是找到第 n 个 Icosidigonal 数 (Isdn)。
多边形有许多多边形,取决于它们的共形数列。在数学中,有许多gonal数,icosidigonal数就是其中之一,这些数有22边的多边形(icosidigon)。二十四角数属于比喻数。它们有一个公共点,其他点图案排列在第 n 个嵌套的 icosidigon 图案中。
例子 :

二十四角数22

第 n 个 Icosidigonal 数的公式:

\begin{math}  Isd_{n}=((20n^2)-18n)/2 \end{math}

C++
// C++ program to find nth Icosidigonal
// number
#include 
using namespace std;
 
// Function to calculate Icosidigonal number
int icosidigonal_num(long int n)
{
    // Formula for finding
    // nth Icosidigonal number
    return (20 * n * n - 18 * n) / 2;
}
 
// Driver function
int main()
{
    long int n = 4;
    cout << n << "th Icosidigonal number :" << icosidigonal_num(n);
    cout << endl;
    n = 8;
    cout << n << "th Icosidigonal number:" << icosidigonal_num(n);
    return 0;
}


Java
// Java program to find nth
// Icosidigonal number
import java.io.*;
 
class GFG
{
     
    // Function to calculate
    // Icosidigonal number
    static int icosidigonal_num(int n)
    {
         
    // Formula for finding
    // nth Icosidigonal number
     
    return (20 * n * n - 18 * n) / 2;
    }
 
// Driver Code
public static void main (String[] args)
{
 
    int n = 4;
    System.out.print (n + "th Icosidigonal number :");
    System.out.println (icosidigonal_num(n));
 
    n = 8;
    System.out.print (n + "th Icosidigonal number :");
    System.out.println (icosidigonal_num(n));
}
}
 
// This code is contributed by ajit


Python 3
# python 3 program to find
# nth Icosidigonal number
 
# Function to calculate
# Icosidigonal number
def icosidigonal_num(n) :
     
    # Formula for finding
    # nth Icosidigonal number
    return (20 * n * n -
            18 * n) // 2
 
# Driver Code
if __name__ == '__main__' :
         
    n = 4
    print(n,"th Icosidigonal " +
                    "number : ",
            icosidigonal_num(n))
    n = 8
    print(n,"th Icosidigonal " +
                    "number : ",
            icosidigonal_num(n))
     
# This code is contributed m_kit


C#
// C# program to find nth
// Icosidigonal number
using System;
 
class GFG
{
     
    // Function to calculate
    // Icosidigonal number
    static int icosidigonal_num(int n)
    {
         
    // Formula for finding
    // nth Icosidigonal number
    return (20 * n * n -
            18 * n) / 2;
    }
 
// Driver Code
static public void Main ()
{
int n = 4;
Console.Write(n + "th Icosidigonal " +
                          "number :");
Console.WriteLine(icosidigonal_num(n));
 
n = 8;
Console.Write (n + "th Icosidigonal "+
                          "number :");
Console.WriteLine(icosidigonal_num(n));
}
}
 
// This code is contributed by ajit


PHP


Javascript


输出 :

4th Icosidigonal number :124
8th Icosidigonal number:568

时间复杂度: O(1)
辅助空间: O(1)

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

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