📜  Icosikaipentagon数

📅  最后修改于: 2021-05-06 08:41:49             🧑  作者: Mango

给定数字N ,任务是找到Nicosikaipentagon数。

例子:

方法:第N个二十烷五角形数由下式给出:

  • S面多边形的第N个项= \frac{((S - 2)N^2 - (S - 4)N)}{2}
  • 因此,25个面的多边形的第N个项由下式给出:

下面是上述方法的实现:

C++
// C++ program to find the N-th
// Icosikaipentagon Number
   
#include 
using namespace std;
   
// Function to find the N-th
// icosikaipentagon Number
int icosikaipentagonNum(int N)
{
    return (23 * N * N - 21 * N)
           / 2;
}
   
// Driver code
int main()
{
    int n = 3;
    cout << "3rd icosikaipentagon Number is "
         << icosikaipentagonNum(n);
   
    return 0;
}


Java
// Java program to find N-th
// icosikaipentagon number
class GFG{
 
// Function to find the nth
// icosikaipentagon number
static int icosikaipentagonNum(int N)
{
    return (23 * N * N - 21 * N) / 2;
}
 
// Driver code
public static void main(String[] args)
{
    int n = 3;
    System.out.print("3rd icosikaipentagon Number is " +
                                icosikaipentagonNum(n));
}
}
 
// This code is contributed by shubham


Python3
# Python3 program to find the N-th
# icosikaipentagon number
 
# Function to find the N-th
# icosikaipentagon number
def icosikaipentagonNum(N):
 
    return (23 * N * N - 21 * N) // 2
 
# Driver code
n = 3
print("3rd icosikaipentagon Number is ",
                 icosikaipentagonNum(n))
 
# This code is contributed by yatinagg


C#
// C# program for the above approach
using System;
class GFG{
 
// Finding the nth chiliagon number
static int Icosikaipentagon(int n)
{
    return (23 * n * n - 21 * n) / 2;
}
 
// Driver code
public static void Main()
{
    int n = 3;
    Console.Write("3rd Icosikaipentagon Number is = " +
                                  Icosikaipentagon(n));
}
}
 
// This code is contributed by shivanisinghss2110


Javascript


输出:
3rd icosikaipentagon Number is 72

时间复杂度: O(1)

辅助空间: O(1)

参考: http : //www.2dcurves.com/line/linep.html