📜  五角形第二个数字

📅  最后修改于: 2021-05-04 16:52:34             🧑  作者: Mango

第二个五边形数字是对象的集合,可以以规则五边形的形式排列。
五角形的第二个系列是:

查找第二个五角形系列的N

给定整数N。任务是找到第二个五边形级数的第N个项。
例子

方法:想法是找到可以通过以下观察得出的系列的通用术语:

因此,该系列的第N个项为\frac{n*(3*n+1)}{2}
下面是上述方法的实现:

C++
// C++ implementation to
// find N-th term in the series
 
#include 
#include 
using namespace std;
 
// Function to find N-th term
// in the series
void findNthTerm(int n)
{
    cout << n * (3 * n + 1) / 2
         << endl;
}
 
// Driver code
int main()
{
    int N = 4;
    findNthTerm(N);
 
    return 0;
}


Java
// Java implementation to
// find N-th term in the series
class GFG{
 
// Function to find N-th term
// in the series
static void findNthTerm(int n)
{
    System.out.print(n * (3 *
                     n + 1) / 2 + "\n");
}
 
// Driver code
public static void main(String[] args)
{
    int N = 4;
    findNthTerm(N);
}
}
 
// This code is contributed by 29AjayKumar


Python3
# Python3 implementation to
# find N-th term in the series
 
# Function to find N-th term
# in the series
def findNthTerm(n):
 
    print(n * (3 * n + 1) // 2, end = " ");
 
# Driver code
N = 4;
findNthTerm(N);
 
# This code is contributed by Code_Mech


C#
// C# implementation to
// find N-th term in the series
using System;
class GFG{
 
// Function to find N-th term
// in the series
static void findNthTerm(int n)
{
    Console.Write(n * (3 *
                  n + 1) / 2 + "\n");
}
 
// Driver code
public static void Main()
{
    int N = 4;
    findNthTerm(N);
}
}
 
// This code is contributed by Code_Mech


Javascript


输出:
26

参考: https : //oeis.org/A005449