📌  相关文章
📜  求出2 * 3 * 5、3 * 5 * 7、4 * 7 * 9,…的序列的前N个项的总和。

📅  最后修改于: 2021-05-05 02:33:14             🧑  作者: Mango

给定整数N ,任务是找到该系列的前N个项的总和:

例子:

方法:让级数的NT n 。通过观察序列的N项,可以很容易地找到该序列的总和:

前n个项的和( S n )可以通过

下面是上述方法的实现:

C++
// C++ program to find sum of the
// first n terms of the given series
#include 
using namespace std;
 
// Function to return the sum of the
// first n terms of the given series
int calSum(int n)
{
    // As described in the approach
    return (n * (2 * n * n * n + 12 * n * n + 25 * n + 21)) / 2;
}
 
// Driver code
int main()
{
    int n = 3;
    cout << calSum(n);
    return 0;
}


Java
// Java program to find sum of the
// first n terms of the given series
class GFG {
 
    // Function to return the sum of the
    // first n terms of the given series
    static int calSum(int n)
    {
 
        // As described in the approach
        return (n * (2 * n * n * n + 12 * n * n + 25 * n + 21)) / 2;
    }
 
    // Driver Code
    public static void main(String args[])
    {
        int n = 3;
        System.out.println(calSum(n));
    }
}


Python
# C++ program to find sum of the
# first n terms of the given series
 
# Function to return the sum of the
# first n terms of the given series
def calSum(n):
     
    # As described in the approach
    return (n*(2 * n*n * n + 12 * n*n + 25 * n + 21))/2;
 
# Driver Code
n = 3
print(calSum(n))


C#
// C# program to find sum of the
// first n terms of the given series
using System;
 
class GFG {
 
    // Function to return the sum of the
    // first n terms of the given series
    static int calSum(int n)
    {
 
        // As described in the approach
        return (n * (2 * n * n * n + 12 * n * n + 25 * n + 21)) / 2;
    }
 
    // Driver code
    static public void Main()
    {
        int n = 3;
        Console.WriteLine(calSum(n));
    }
}


PHP


Javascript


输出:
387