Find the Nth term of the Mysterious series.
N    Nth term
1    5
2    10
3    26
4    50
5    122
.
.
.
10    842
Example 1:
Input: N = 1
Output: 5 
Explanation: First term of the series is 5.
Example 2:
Input: N = 2
Output: 10
Explanation: Second term of the series is 10. 
Your Task:  
You dont need to read input or print anything. Complete the function nthMysterious() which takes N as input parameter and returns the Nth term of the Mysterious series.
Expected Time Complexity: O(nlogn)
Expected Auxiliary Space: O(n)
Constraints:
1<= N <=10^{3}

Difficulty: EASY
Tags: Number theory

Mathematics
Expected Time Complexity: O(nlogn)
Expected Auxiliary Space: O(n)

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

Solutions:
import math

class Solution:

	def isPrime(self, n):
		if n == 0 or n == 1:
			return False
		else:
			lim = int(math.sqrt(n)) + 1
			for i in range(2, lim):
				if n % i == 0:
					return False
			return True

	def nthMysterious(self, N):
		(res, c) = ([], 0)
		for i in range(2, int(100000.0) + 1):
			if self.isPrime(i):
				res.append(i * i + 1)
				c += 1
			if c == N:
				return res[N - 1]


import math

class Solution:

	def nthMysterious(self, N):
		j = 2
		i = 0
		while i < N:
			c = 0
			k = int(math.sqrt(j))
			for p in range(2, k + 1):
				if j % p == 0:
					c = 1
					break
			if c == 0:
				l = j
				i = i + 1
			j = j + 1
		return l ** 2 + 1


def isprime(x):
	for i in range(2, int(x ** (1 / 2)) + 1):
		if x % i == 0:
			return False
		else:
			continue
	return True

class Solution:

	def nthMysterious(self, n):
		a = []
		i = 2
		k = 0
		while k < n:
			if isprime(i) == True:
				k = k + 1
				p = i
				i = i + 1
			else:
				i = i + 1
		return p ** 2 + 1


class Solution:

	def nthMysterious(self, N):

		def nthPrime(n):

			def isPrime(n):
				for i in range(5, int(n ** 0.5) + 1, 2):
					if not n % i:
						return False
				return True
			if n < 3:
				return n + 1
			p = 5
			for i in range(4, n + 1):
				p += (p + 3) % 6
				while not isPrime(p):
					p += (p + 3) % 6
			return p


import math

class Solution:

	def nthMysterious(self, n):

		def isPrime(x):
			for i in range(2, int(math.sqrt(x)) + 1):
				if x % i == 0:
					return False
			return True
		ans = 1
		arr = []
		i = 2
		while len(arr) < n:
			if isPrime(i):
				arr.append(i)
			i += 1
		return arr[n - 1] ** 2 + 1


class Solution:

	def nthMysterious(self, N):
		x = N
		(n, c) = (1, 0)
		while c < x:
			n += 1
			for i in range(2, n + 1):
				if n % i == 0:
					break
			if i == n:
				c = c + 1
		return n ** 2 + 1


class Solution:

	def isprime(self, N):
		if N <= 1:
			return False
		k = int(N ** 0.5)
		for i in range(2, k + 1):
			if N % i == 0:
				return False
		return True

	def nthMysterious(self, N):
		i = 2
		c = 0
		while True:
			if self.isprime(i):
				c += 1
			if c == N:
				return i * i + 1
			i += 1


import math

class Solution:

	def isPrime(self, n):
		if n <= 1:
			return False
		max_div = math.floor(math.sqrt(n))
		for i in range(2, max_div + 1):
			if n % i == 0:
				return False
		return True

	def nthMysterious(self, N):
		v = []
		c = 0
		for i in range(2, 100000):
			if self.isPrime(i):
				v.append(i * i + 1)
				c += 1
			if c == N:
				return v[N - 1]


def isprime(n):
	if n <= 1:
		return False
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True

class Solution:

	def nthMysterious(self, N):
		l = [1, 2 * 2 + 1, 3 * 3 + 1, 5 * 5 + 1]
		for i in range(7, 100001):
			x1 = isprime(i)
			if x1:
				l.append(i * i + 1)
			if len(l) > N:
				break
		return l[N]


class Solution:

	def prime(self, n):
		for i in range(2, n):
			if n % i == 0:
				return 0
		if n % n == 0 and n % 1 == 0:
			return 1

	def nthMysterious(self, N):
		l = []
		i = 2
		while len(l) != N:
			a = self.prime(i)
			if a == 1:
				l.append(i ** 2 + 1)
			i = i + 1
		return l[N - 1]


class Solution:

	def nthMysterious(self, k):
		c = 0
		n = 2
		m = 0
		while 1:
			p = 1
			for i in range(2, int(n ** 0.5) + 1):
				if n % i == 0:
					p = 0
					break
			if p == 1:
				c = c + 1
				m = n
			if c == k:
				break
			n = n + 1
		return m ** 2 + 1


class Solution:

	def nthMysterious(self, N):
		l = []
		i = 2
		while len(l) != N:
			for j in range(2, i // 2 + 1):
				if i % j == 0:
					break
			else:
				l.append(i)
			i += 1
		return l[N - 1] ** 2 + 1


class Solution:

	def prime(self, n):
		for i in range(2, n // 2 + 1):
			if n % i == 0:
				return 0
		return 1

	def nthMysterious(self, n):
		i = 2
		c = 0
		while n != c:
			if self.prime(i):
				k = i
				c = c + 1
			i = i + 1
		return k * k + 1


from math import sqrt
from itertools import compress

class Solution:
	N = 10 ** 4 + 1
	list_of_prime = []
	bool_prime_list = [True, False, True] + [True, False] * ((N - 3) // 2)
	list_created = False

	def __init__(self):
		if not Solution.list_created:
			Solution.utility()

	@staticmethod
	def utility():
		for i in range(2, int(sqrt(Solution.N)) + 1):
			if Solution.bool_prime_list[i]:
				j = i ** 2
				while j < Solution.N:
					Solution.bool_prime_list[j] = False
					j += i
		Solution.list_of_prime = list(compress(list(range(0, Solution.N + 1)), Solution.bool_prime_list))

	def nthMysterious(self, N):
		return Solution.list_of_prime[N] ** 2 + 1


def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i += 6
	return True

class Solution:

	def nthMysterious(self, N):
		li = list()
		count = 0
		for i in range(100000):
			if isPrime(i):
				li.append(i * i + 1)
				count += 1
			if count == N:
				return li[N - 1]