Given a number N.Find the sum of fifth powers of natural numbers till N i.e. 1^{5}+2^{5}+3^{5}+..+N^{5}.
Example 1:
Input:
N=2
Output:
33
Explanation:
The sum is calculated as 1^{5}+2^{5}=1+32=33.
Example 2:
Input:
N=3
Output:
276
Explanation:
The sum is calculated as 1^{5}+2^{5}+3^{5}
=1+32+243=276.
Your Task:
You don't need to read input or print anything.Your task is to complete the function sumOfFifthPowers() which takes an integer N as input parameter and returns the sum of the fifth powers of Natural numbers till N.
Expected Time Complexity:O(1)
Expected Auxillary Space:O(1)
Constraints:
1<=N<=1000

Source: geeksforgeeks | Difficulty: EASY
Tags: Number theory

Mathematics

Starter code: #User function Template for python3

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

Solutions:
class Solution:

	def sumOfFifthPowers(self, n):
		return n * n * (n + 1) * (n + 1) * (2 * n * n + 2 * n - 1) // 12


class Solution:

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


class Solution:

	def sumOfFifthPowers(self, n):
		sq = n * n
		sq1 = (n + 1) * (n + 1)
		f = sq * sq1 * (2 * sq + (2 * n - 1)) // 12
		return f


class Solution:

	def sumOfFifthPowers(self, N):
		c = []
		for i in range(1, N + 1):
			c.append(pow(i, 5))
		return sum(c)


class Solution:

	def sumOfFifthPowers(self, N):
		d = 0
		k = 0
		while k <= N:
			d = d + k ** 5 % 10000000000000000000000007
			k = k + 1
		return d % 1000000000000000000000000007


class Solution:

	def sumOfFifthPowers(self, N):
		return (N * (N + 1)) ** 2 * (2 * N ** 2 + 2 * N - 1) // 12


class Solution:

	def sumOfFifthPowers(self, N):
		return (2 * N * N * N * N * N * N + 6 * N * N * N * N * N + 5 * N * N * N * N - N * N) // 12


class Solution:

	def sumOfFifthPowers(self, n):
		return (2 * n ** 6 + 6 * n ** 5 + 5 * n ** 4 - n ** 2) // 12


class Solution:

	def sumOfFifthPowers(self, N):
		return N * N * (N + 1) * (N + 1) * (2 * N * N + 2 * N - 1) // 12
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.sumOfFifthPowers(N))


class Solution:

	def sumOfFifthPowers(self, N):
		x = N ** 6
		y = N ** 5
		z = N ** 4
		return (2 * x + 6 * y + z * 5 - N * N) // 12