Given a number N, the task is to find the sum of all the elements from all possible subsets of a set formed by first N natural numbers.
Example 1:
Input:
N = 2
Output:
6
Explanation:
Possible subsets are {{1}, {2}, {1, 2}}.
Sum of elements in the subsets is 
1 + 2 + 1 + 2 = 6.
Example 2:
Input:
N = 3
Output:
24
Explanation:
Possible subsets are 
{{1},{2},{3},{1,2},{2,3},{1,3},{1,2,3}}.
Sum of elements in the subsets is 
1+2+3+1+2+2+3+1+3+1+2+3 = 24
Your Task:  
You don't need to read input or print anything. Your task is to complete the function sumOfSubsets() which takes an integer N as an input parameter and return the sum of all the elements from all possible subsets of a set formed by first N natural numbers.
Expected Time Complexity: O(logN)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N <= 50

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3



class Solution:

    def sumOfSubsets(self, N):

    	#code here

Solutions:
class Solution:

	def sumOfSubsets(self, N):
		a = sum(range(1, N + 1))
		b = 2 ** (N - 1)
		return a * b


class Solution:

	def sumOfSubsets(self, N):
		k = 2 ** (N - 1)
		c = 0
		for i in range(1, N + 1):
			c += i * k
		return c


class Solution:

	def sumOfSubsets(self, N):
		return N * (N + 1) * pow(2, N - 1) // 2


class Solution:

	def sumOfSubsets(self, N):
		n = N
		n = n * (n + 1) / 2
		return int(n * 2 ** (N - 1))


import numpy as np

class Solution:

	def sumOfSubsets(self, N):
		return N * (N + 1) // 2 * pow(2, N - 1)


class Solution:

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


class Solution:

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


class Solution:

	def sumOfSubsets(self, N):
		s = 0
		p = 2 ** (N - 1)
		for i in range(1, N + 1):
			s = s + p * i
		return s


class Solution:

	def sumOfSubsets(self, N):
		if N > 2:
			H = 2 ** (N - 1)
			sum1 = 0
			for i in range(1, N + 1):
				sum1 = sum1 + int(i * H)
			return sum1
		if N == 2:
			return 6
		if N == 1:
			return 1