My friend generated a series 1 4 8 9 12 17 25 28 .... . Each element of this series is known as "Dory". Your task is to find out whether a number n is Dory or not.
NOTE: If n is "Dory", then return 1 else return 0.
Example 1:
Input: n = 4
Output: 1 
Explanation: 4 is Dory because 
its present in the series.
Example 2:
Input: n = 7
Output: 0
Explanation: 7 is not Dory because
its not present in the series.
Your Task:  
You dont need to read input or print anything. Complete the function nisDoryOrNot() which takes n as input parameter and returns 1 If n is "Dory" else return 0.
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
Constraints:
1<= n <=10^{9}

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3
class Solution:
    def nisDoryOrNot (ob, n):
        # code here 

Solutions:
import math

class Solution:

	def nisDoryOrNot(ob, n):
		x = 5 * n - 4
		y = 5 * n + 4
		x1 = int(math.sqrt(x))
		y1 = int(math.sqrt(y))
		if x1 ** 2 == x or y1 ** 2 == y:
			return 1
		return 0


import math

class Solution:

	def nisDoryOrNot(ob, n):
		x = 5 * n + 4
		y = 5 * n - 4
		root1 = math.sqrt(x)
		root2 = math.sqrt(y)
		if int(root1 + 0.5) ** 2 == x or int(root2 + 0.5) ** 2 == y:
			return 1
		else:
			return 0


import math

class Solution:

	def nisDoryOrNot(ob, n):
		s1 = 5 * n + 4
		s2 = 5 * n - 4
		x1 = math.sqrt(s1)
		x2 = math.sqrt(s2)
		if int(x1 + 0.5) ** 2 == s1 or int(x2 + 0.5) ** 2 == s2:
			return 1
		else:
			return 0


class Solution:

	def nisDoryOrNot(ob, n):
		(n1, n2) = (5 * n - 4, 5 * n + 4)
		(n3, n4) = (int(n1 ** 0.5), int(n2 ** 0.5))
		if n1 == n3 ** 2 or n2 == n4 ** 2:
			return 1
		return 0


class Solution:

	def nisDoryOrNot(ob, n):
		x = 5 * n - 4
		y = 5 * n + 4
		x1 = int(x ** 0.5)
		y1 = int(y ** 0.5)
		if x1 * x1 == x or y1 * y1 == y:
			return 1
		return 0


import math

class Solution:

	def checkSquare(self, n):
		return True if int(math.sqrt(n)) ** 2 == n else False

	def nisDoryOrNot(ob, n):
		if ob.checkSquare(5 * n - 4) or ob.checkSquare(5 * n + 4):
			return 1
		return 0
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		n = int(input())
		ob = Solution()
		print(ob.nisDoryOrNot(n))


import math

class Solution:

	def nisDoryOrNot(ob, n):
		import math

		def func(n):
			x = 5 * n + 4
			y = 5 * n - 4
			root1 = math.sqrt(x)
			root2 = math.sqrt(y)
			if int(root1 + 0.5) ** 2 == x or int(root2 + 0.5) ** 2 == y:
				return True
			return False
		if func(n) == True:
			return 1
		return 0


class Solution:

	def nisDoryOrNot(ob, n):
		num1 = 5 * n + 4
		num2 = 5 * n - 4
		if num1 ** (1 / 2) == int(num1 ** (1 / 2)):
			return 1
		elif num2 ** (1 / 2) == int(num2 ** (1 / 2)):
			return 1
		return 0


class Solution:

	def nisDoryOrNot(ob, n):
		x = 5 * n + 4
		y = 5 * n - 4
		u = int(x ** 0.5)
		v = int(y ** 0.5)
		if u ** 2 == x or v ** 2 == y:
			return 1
		return 0


def isPerfectSquare(N):
	if int(N ** 0.5) ** 2 == N:
		return True
	return False

class Solution:

	def nisDoryOrNot(ob, n):
		if isPerfectSquare(5 * n - 4) or isPerfectSquare(5 * n + 4):
			return 1
		return 0