d阶欧拉数序列可以表示为
1, 0, 0, 2, 8, 22, 52, 114, 240, 494, 1004, …..
第N个学期
给定整数N。任务是找到给定级数的第N个项。
例子:
Input: N = 0
Output: 1
term = 1
Input: N = 4
Output: 8
方法:想法是找到二阶欧拉数的通用项。以下是二阶欧拉数的通用项的计算:
0th term = 20 – 2*0 = 1
1st Term = 21 – 2*1 = 0
2nd term = 22 – 2*2 = 0
3rd term = 23 – 2*3 = 2
4th term = 24 – 2*4 = 8
5th term = 25 – 2*5 = 22
.
.
.
Nth term = 2n – 2*n.
Therefore, the Nth term of the series is given as
下面是上述方法的实现:
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 << pow(2, n) - 2 * n << 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.println(Math.pow(2, n) - 2 * n);
}
// Driver code
public static void main(String[] args)
{
int N = 4;
findNthTerm(N);
}
}
// This code is contributed by Pratima Pandey
Python3
# Python3 implementation to
# find N-th term in the series
# Function to find N-th term
# in the series
def findNthTerm(n):
print(pow(2, n) - 2 * n);
# 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(Math.Pow(2, n) - 2 * n);
}
// Driver code
public static void Main()
{
int N = 4;
findNthTerm(N);
}
}
// This code is contributed by Code_Mech
Javascript
输出:
8
参考: OEIS