A given series 3, 5, 9, 11, 15, 17, 21, 27, 29, ... and so on. You need to identify the pattern and determine whether the input number  ( n ) is a part of the given series or not. If yes then return "Yes", otherwise "No".
Example 1:
Input: n = 9
Output: Yes
Explanation: 9 is the part of
the sequence.
Example 2:
Input: n = 8
Output: No
Explanation: 8 is not the part
of the sequence
Your Task:  
You don't need to read input or print anything. Your task is to complete the function isPart() which takes n as inputs and returns the answer.
Expected Time Complexity: O(sqrt(n))
Expected Auxiliary Space: O(1)
Constraints:
1 ≤ n ≤ 10^{6}

Source: geeksforgeeks | Difficulty: MEDIUM
Tags: Mathematics

Starter code: #User function Template for python3





class Solution:

    def isPart (self, n):

        #complete the function here

Solutions:
class Solution:

	def isPart(self, n):
		n += 2
		i = 2
		while i * i <= n:
			if n % i == 0:
				return 'No'
			i += 1
		return 'Yes'


import math

class Solution:

	def isPart(self, n):
		if n % 2 == 0:
			return 'No'
		elif n == 3 or n == 1:
			return 'Yes'
		else:
			lim = int(math.sqrt(n + 2)) + 1
			for i in range(2, lim):
				if (n + 2) % i == 0:
					return 'No'
			return 'Yes'


class Solution:

	def isPart(self, n):
		a = n + 2
		if n % 2 == 0:
			return 'No'
		elif n == 1:
			return 'Yes'
		else:
			for i in range(2, int(a ** 0.5) + 1):
				if a % i == 0:
					return 'No'
			return 'Yes'


import math

class Solution:

	def isPart(self, n):
		x = n + 2
		t = 0
		for i in range(2, int(math.sqrt(x)) + 1):
			if x % i == 0:
				t = 1
				break
		if t == 1:
			return 'No'
		return 'Yes'


class Solution:

	def isPart(self, n):
		if n % 2 == 0:
			return 'No'
		if n == 1:
			return 'Yes'
		else:
			if n >= 3:
				n = n + 2
				for i in range(2, n // 2 + 1):
					if n % i == 0:
						return 'No'
				return 'Yes'
			return 'No'


class Solution:

	def isPart(self, n):
		a = n + 2
		c = 1
		i = 2
		while i * i <= a:
			if a % i == 0:
				c = 0
				break
			i += 1
		if c == 0:
			return 'No'
		else:
			return 'Yes'


class Solution:

	def isPart(self, n):
		if n == 3:
			return 'Yes'
		else:
			N = n + 2
			x = int(n ** 0.5) + 2
			for i in range(2, x):
				if N % i == 0:
					return 'No'
			return 'Yes'


class Solution:

	def isPart(self, n):

		def isPrime(p):
			k = int(p ** 0.5) + 1
			for i in range(3, k, 2):
				if not p % i:
					return False
			return True
		if not n % 2:
			return 'No'
		if isPrime(n + 2):
			return 'Yes'
		return 'No'


import math

class Solution:

	def isPart(self, n):
		if n == 2:
			return 'No'
		k = n + 2
		for i in range(2, math.floor(math.sqrt(n + 2)) + 1):
			if k % i == 0:
				return 'No'
		return 'Yes'


import math

class Solution:

	def isPart(self, n):
		n = n + 2
		for i in range(2, int(math.sqrt(n)) + 1):
			if n % i == 0:
				return 'No'
		return 'Yes'
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		n = int(input())
		ob = Solution()
		print(ob.isPart(n))


class Solution:

	def isPart(self, n):
		p = int((n + 2) ** 0.5)
		c = 0
		for i in range(2, p + 1):
			if (n + 2) % i == 0:
				c += 1
		if c == 0:
			return 'Yes'
		return 'No'
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		n = int(input())
		ob = Solution()
		print(ob.isPart(n))


class Solution:

	def isPart(self, n):
		x = n + 2
		for i in range(2, int(x ** 0.5) + 1):
			if x % i == 0:
				return 'No'
		return 'Yes'


import math

class Solution:

	def isPart(self, n):

		def prime(n):
			for i in range(2, int(math.sqrt(n)) + 1):
				if n % i == 0:
					return False
			return True
		if prime(n + 2):
			return 'Yes'
		return 'No'


from math import sqrt

class Solution:

	def isPart(self, n):
		if n == 1:
			return 'Yes'
		if n == 2 or n == 4 or n == 6:
			return 'No'
		n = n + 2
		for i in range(2, int(sqrt(n)) + 1):
			if n % i == 0:
				return 'No'
		return 'Yes'


class Solution:

	def isPart(self, n):
		op = 'Yes'
		n2 = n + 2
		half = n2 // 2
		for i in range(2, half + 1):
			if n2 % i == 0:
				op = 'No'
				break
		return op


class Solution:

	def isprime(self, x):
		i = 2
		while i * i <= x:
			if x % i == 0:
				return False
			i += 1
		return True

	def isPart(self, n):
		if self.isprime(n + 2):
			return 'Yes'
		return 'No'


class Solution:

	def isPart(self, n):
		a = n + 2
		ns = 'No'
		ys = 'Yes'
		for i in range(2, int(a ** 1 / 2) + 1):
			if a % i == 0:
				return ns
		return ys


class Solution:

	def isPart(self, n):
		ans = 'Yes'
		n = n + 2
		for i in range(2, n):
			if n % i == 0:
				ans = 'No'
				break
		if n == 3:
			ans = 'Yes'
		return ans


class Solution:

	def isPart(self, n):
		t = -1
		a = n + 2
		k = int(a ** 0.5) + 1
		for i in range(2, k):
			if a % i == 0:
				return 'No'
				t = 0
				break
		if t == -1:
			return 'Yes'


import math as m

class Solution:

	def isPart(self, n):
		n = n + 2
		for i in range(2, int(m.sqrt(n)) + 1):
			if n % i == 0:
				return 'No'
		return 'Yes'