Given the series as follows 2 2 4 8 16 512....... Identify the Nth term of the series. Answers can be very large use BigInt in Java.
Example 1:
Input: N = 1
Output: 2 
Explanation: First term of the series is 2.
Example 2:
Input: N = 2
Output: 2
Explanation: Second term of the series is 2. 
Your Task:  
You dont need to read input or print anything. Complete the function NthTerm() which takes N as input parameter and returns the Nth term of the series.
Expected Time Complexity: O(logn*logn)
Expected Auxiliary Space: O(1)
Constraints:
1<= N <=12

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3
class Solution:
    def NthTerm (self, N):
        # code here 

Solutions:
class Solution:

	def NthTerm(self, N):
		if N == 1:
			return 2
		if N == 2:
			return 2
		smallerOut = self.NthTerm(N - 2)
		if N % 2 == 0:
			return smallerOut ** 3
		else:
			return smallerOut ** 2


class Solution:

	def NthTerm(self, N):
		ls = [2, 2]
		pw = 1
		pw2 = 1
		for i in range(N // 2):
			pw = 2 * pw
			num = 2 ** pw
			pw2 = 3 * pw2
			num2 = 2 ** pw2
			ls.extend([num, num2])
		return ls[N - 1]


class Solution:

	def NthTerm(self, N):
		if N == 1 or N == 2:
			return 2
		elif N % 2 != 0:
			po = (N - 1) // 2
			pw = 2 ** po
			return 2 ** pw
		else:
			po = N // 2 - 1
			pw = 3 ** po
			return 2 ** pw


class Solution:

	def NthTerm(self, N):
		sum = 2
		i = N
		if N % 2 != 0:
			while i > 1:
				sum = sum ** 2
				i -= 2
		else:
			while i > 2:
				sum = sum ** 3
				i -= 2
		return sum


class Solution:

	def NthTerm(self, N):
		if N == 1 or N == 2:
			return 2
		elif N % 2 != 0:
			p = (N - 1) // 2
			p1 = 2 ** p
			return 2 ** p1
		else:
			p = N // 2 - 1
			p1 = 3 ** p
			return 2 ** p1


class Solution:

	def NthTerm(self, N):
		num = 2
		if N % 2 == 0:
			for i in range(1, N // 2):
				num = num ** 3
			return num
		else:
			for i in range(1, N // 2 + 1):
				num = num ** 2
			return num


class Solution:

	def NthTerm(self, N):
		if N == 1 or N == 2:
			return 2
		elif N % 2 != 0:
			x = (N - 1) // 2
			y = 2 ** x
			return 2 ** y
		else:
			x = N // 2 - 1
			y = 3 ** x
			return 2 ** y


class Solution:

	def NthTerm(self, n):
		d = {1: 2, 2: 2}
		for i in range(3, n + 1):
			if i % 2:
				d[i] = d[i - 2] ** 2
			else:
				d[i] = d[i - 2] ** 3
		return d[n]


class Solution:

	def NthTerm(self, n):
		if n % 2 == 1:
			return 2 ** 2 ** (n // 2)
		else:
			return 2 ** 3 ** ((n - 1) // 2)


class Solution:

	def NthTerm(self, n):
		if n == 1 or n == 2:
			return 2
		k = 2
		if n % 2 == 1:
			for i in range(0, n // 2):
				k = pow(k, 2)
			return k
		else:
			for i in range(0, n // 2 - 1):
				k = pow(k, 3)
			return k


class Solution:

	def NthTerm(self, N):
		p = int((N - 1) / 2)
		if N % 2:
			p = 2 ** p
		else:
			p = 3 ** p
		return 2 ** p


class Solution:

	def NthTerm(self, N):
		if N == 1 or N == 2:
			return 2
		elif N % 2 != 0:
			power = (N - 1) // 2
			res = 2 ** power
			return 2 ** res
		else:
			power = N // 2 - 1
			res = 3 ** power
			return 2 ** res


class Solution:

	def NthTerm(self, n):
		if n == 1 or n == 2:
			return 2
		elif n % 2 != 0:
			p = (n - 1) // 2
			w = 2 ** p
			return 2 ** w
		else:
			p = n // 2 - 1
			w = 3 ** p
			return 2 ** w


class Solution:

	def NthTerm(self, N):
		if N == 1:
			return 2
		elif N == 2:
			return 2
		evencube = 2
		oddsquare = 2
		if N % 2 == 0:
			for i in range(1, int(N / 2)):
				evencube = evencube ** 3
			return evencube
		else:
			for i in range(1, int(N // 2 + 1)):
				oddsquare = oddsquare ** 2
			return oddsquare


class Solution:

	def NthTerm(self, N):
		if N & 1 == 1:
			po = (N - 1) // 2
			pw = 2 ** po
			return 2 ** pw
		po = N // 2 - 1
		pw = 3 ** po
		return 2 ** pw


class Solution:

	def NthTerm(self, N):
		N -= 1
		ans = 2
		ec = 0
		oc = 0
		if N % 2 == 0:
			ec = N // 2
		else:
			oc = (N + 1) // 2
		if ec != 0:
			for i in range(0, ec):
				ans = ans ** 2
			return ans
		for i in range(0, oc - 1):
			ans = ans ** 3
		return ans


class Solution:

	def NthTerm(self, N):
		res = 2
		if N == 1 or N == 2:
			return res
		elif N % 2 != 0:
			for i in range(3, N + 1, 2):
				res = pow(res, 2)
			return res
		else:
			for i in range(4, N + 1, 2):
				res = pow(res, 3)
			return res


class Solution:

	def NthTerm(self, n):

		def odd(n):
			if n == 1:
				return 2
			return odd(n - 2) * odd(n - 2)

		def even(n):
			if n == 2:
				return 2
			return even(n - 2) * even(n - 2) * even(n - 2)
		if n % 2 != 0:
			return odd(n)
		else:
			return even(n)


class Solution:

	def NthTerm(self, N):
		res = 2
		if N == 1 or N == 2:
			return res
		elif N % 2 == 0:
			for i in range(4, N + 1, 2):
				res = res ** 3
		else:
			for i in range(3, N + 1, 2):
				res = res ** 2
		return res
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print('%.0f' % ob.NthTerm(N))


class Solution:

	def NthTerm(self, N):
		if N % 2:
			return 2 ** 2 ** (N // 2)
		else:
			return 2 ** 3 ** (N // 2 - 1)
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print('%.0f' % ob.NthTerm(N))


class Solution:

	def NthTerm(self, n):
		if n <= 1:
			return 2
		if n % 2 != 0:
			i = 0
			value = 1
			while i < n - 1:
				value *= 2
				i += 2
			return 2 ** value
		else:
			i = 1
			value = 1
			while i < n - 1:
				value *= 3
				i += 2
			return 2 ** value
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print('%.0f' % ob.NthTerm(N))


class Solution:

	def NthTerm(self, n):
		if n == 1 or n == 2:
			return 2
		elif n % 2 != 0:
			po = (n - 1) // 2
			pw = 2 ** po
			return 2 ** pw
		else:
			po = n // 2 - 1
			pw = 3 ** po
			return 2 ** pw
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print('%.0f' % ob.NthTerm(N))


class Solution:

	def NthTerm(self, n):
		pre = 2
		res = None
		if not n & 1:
			for i in range(1, n // 2):
				res = pre ** 3
				pre = res
		else:
			for i in range(n // 2):
				res = pre ** 2
				pre = res
		return res


class Solution:

	def NthTerm(self, N):
		x = N // 2
		if N & 1 != 0:
			return pow(2, pow(2, x))
		return pow(2, pow(3, x - 1))


class Solution:

	def NthTerm(self, N):
		if N % 2 == 1:
			return 2 ** 2 ** (N // 2)
		return 2 ** 3 ** (N // 2 - 1)


import math

class Solution:

	def NthTerm(self, N):
		if N & 1:
			N = math.ceil(N / 2)
			return 2 ** 2 ** (N - 1)
		else:
			N = N // 2
			return 2 ** 3 ** (N - 1)


class Solution:

	def NthTerm(self, N):
		a = int(N / 2)
		if N == 1 or N == 2:
			return 2
		if N % 2 == 0:
			return 2 ** 3 ** (a - 1)
		return 2 ** 2 ** a