Given and integer N.Calculate the sum of series 1^{3} + 2^{3} + 3^{3} + 4^{3} + … till N-th term.
Example 1:
Input:
N=5
Output:
225
Explanation:
1^{3}+2^{3}+3^{3}+4^{3}+5^{3}=225
Example 2:
Input:
N=7
Output:
784
Explanation:
1^{3}+2^{3}+3^{3}+4^{3}+5^{3}+6^{3}+7^{3}=784
Your Task:
You don't need to read input or print anything.Your task is to complete the function sumOfSeries() which takes the integer N as parameter and returns the sum of the cubes of the first N natural numbers.
Expected Time Complexity:O(1)
Expected Auxillary Space:O(1)
Constraints:
1<=N<=50000

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3

class Solution:
    def sumOfSeries(self,N):
        #code here

Solutions:
class Solution:

	def sumOfSeries(self, n):
		return n ** 2 * (n + 1) ** 2 // 4


class Solution:

	def sumOfSeries(self, N):
		sum = N * (N + 1) // 2
		return sum ** 2


class Solution:

	def sumOfSeries(self, N):
		seriesSum = 0
		for i in range(1, N + 1):
			seriesSum += i * i * i
		return seriesSum


class Solution:

	def sumOfSeries(self, N):
		sum_of_cubes = (N * (N + 1) // 2) ** 2
		return sum_of_cubes


class Solution:

	def sumOfSeries(self, N):
		ans = (N * (N + 1)) ** 2 // 4
		return ans


class Solution:

	def sumOfSeries(self, n):
		s = 0
		for i in range(1, n + 1):
			s += i * i * i
		return s


class Solution:
	import sys
	sys.setrecursionlimit(6000)

	def sumOfSeries(self, N):
		return (N * (N + 1) // 2) ** 2


class Solution:

	def sumOfSeries(self, N):
		a = 0
		a = N * (N + 1) // 2
		return a * a


class Solution:

	def sumOfSeries(self, N):
		sumAll = N * (N + 1) // 2
		return pow(sumAll, 2)


class Solution:

	def sumOfSeries(self, N):
		a = (N + 1) ** 2
		b = N ** 2
		c = a * b
		return c // 4


class Solution:

	def sumOfSeries(self, N):
		sum = N * N * (N + 1) * (N + 1) // 4
		return sum


from math import pow

class Solution:

	def sumOfSeries(self, N):
		return (N * (N + 1) // 2) ** 2


class Solution:

	def sumOfSeries(self, N):
		d = (N * (N + 1) // 2) ** 2
		return d


class Solution:

	def sumOfSeries(self, n):
		k = n * (n + 1) // 2
		return k ** 2


class Solution:

	def sumOfSeries(self, n):
		return (N * (N + 1) // 2) ** 2


class Solution:

	def sumOfSeries(self, N):
		return sum([i for i in range(1, N + 1)]) ** 2


class Solution:
	s = 0

	def sumOfSeries(self, N):
		p = (N * (N + 1) // 2) ** 2
		return p


class Solution:

	def sumOfSeries(self, n):
		sum = int((n * (n + 1) // 2) ** 2)
		return sum


class Solution:

	def sumOfSeries(self, N):
		ans = N * (N + 1) // 2
		return pow(ans, 2)


class Solution:

	def sumOfSeries(self, N):
		tot = N * (N + 1) // 2
		return pow(tot, 2)


import math

class Solution:

	def sumOfSeries(self, N):
		c = 0
		for i in range(N + 1):
			c += i * i * i
		return c


class Solution:

	def sumOfSeries(self, N):
		S = N ** 2 * (N + 1) ** 2 // 4
		return S


class Solution:

	def sumOfSeries(self, N):
		sum = 0
		for i in range(1, N + 1):
			i_sum = i * i * i
			sum = sum + i_sum
		return sum


class Solution:

	def sumOfSeries(self, N):
		k = N * (N + 1) // 2
		return int(k ** 2)


class Solution:

	def sumOfSeries(self, N):
		x = (N * (N + 1) // 2) ** 2
		return x


class Solution:

	def sumOfSeries(self, N):
		if N == 1:
			return 1
		else:
			return (N * (N + 1) // 2) ** 2