Check if a given number N is the Fibonacci number. A Fibonacci number is a number that occurs in the Fibonacci series.
 
Example 1:
Input:
N = 34
Output:
Yes
Explanation:
34 is one of the numbers 
of the Fibonacci series.
 
Example 2:
Input:
N = 41
Output:
No
Explanation:
41 is not in the numbers 
of the Fibonacci series.
 
 
Your Task:
You don't need to read input or print anything. Your task is to complete the function checkFibonacci() which takes an integer N and returns a string "Yes" if it is a Fibonacci number else "No".
 
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
 
Constraints:
1 <= N <= 100

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3

class Solution:

    def checkFibonacci (ob,N):

        # code here 

Solutions:
class Solution:

	def checkFibonacci(ob, N):
		if N == 0 or N == 1:
			return 'Yes'
		first = 0
		second = 1
		for i in range(N):
			nextterm = first + second
			if nextterm == N:
				return 'Yes'
			first = second
			second = nextterm
		return 'No'


import math

class Solution:

	def checkFibonacci(ob, N):
		a = math.sqrt(5 * N * N - 4)
		b = math.sqrt(5 * N * N + 4)
		if math.ceil(a) == math.floor(a):
			return 'Yes'
		if math.ceil(b) == math.floor(b):
			return 'Yes'
		return 'No'


class Solution:

	def checkFibonacci(ob, N):
		a = 0
		b = 1
		c = a + b
		while c <= N:
			if c == N:
				return 'Yes'
			a = b
			b = c
			c = a + b
		return 'No'


class Solution:

	def checkFibonacci(ob, N):
		if N == 0 or N == 1:
			return 'Yes'
		temp = 0
		fib = [0, 1]
		while temp < N:
			temp = fib[-2] + fib[-1]
			fib.append(temp)
		if fib[-1] == N:
			return 'Yes'
		else:
			return 'No'


class Solution:

	def checkFibonacci(ob, N):
		li = []
		a1 = 0
		a2 = 1
		li.append(a1)
		li.append(a2)
		for i in range(2, N + 2):
			a3 = a1 + a2
			li.append(a3)
			a1 = a2
			a2 = a3
		if N in li:
			return 'Yes'
		return 'No'


import math

class Solution:

	def checkFibonacci(ob, N):
		n1 = 5 * N ** 2 + 4
		n2 = 5 * N ** 2 - 4
		if math.sqrt(n1).is_integer() or math.sqrt(n2).is_integer():
			return 'Yes'
		else:
			return 'No'


class Solution:

	def checkFibonacci(ob, N):
		l = [0, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
		if N in l:
			return 'Yes'
		else:
			return 'No'


class Solution:

	def checkFibonacci(ob, N):
		res1 = 5 * N ** 2 + 4
		res2 = 5 * N ** 2 - 4
		a = int(res1 ** 0.5)
		b = int(res2 ** 0.5)
		if a * a == res1 or b * b == res2:
			return 'Yes'
		else:
			return 'No'


class Solution:

	def checkFibonacci(ob, N):
		a = 0
		b = 1
		c = 0
		res = []
		for i in range(N):
			c = a + b
			res.append(c)
			a = b
			b = c
		if N in res:
			return 'Yes'
		else:
			return 'No'


class Solution:

	def checkFibonacci(ob, N):
		f1 = 0
		f2 = 1
		f3 = f1 + f2
		if N == f1 or N == f2 or N == f3:
			return 'Yes'
		while f3 != N:
			f1 = f2
			f2 = f3
			f3 = f1 + f2
			if f3 == N:
				return 'Yes'
			elif f3 > N:
				return 'No'


class Solution:

	def checkFibonacci(ob, n):
		l = [0, 1, 1]
		for i in range(n):
			l.append(l[-1] + l[-2])
		if n in l:
			return 'Yes'
		else:
			return 'No'


class Solution:

	def checkFibonacci(ob, N):
		if N < 1:
			return 'No'
		else:
			fib_list = [1, 1]
			sum = 0
			for i in range(N):
				fib = fib_list[i] + fib_list[i + 1]
				fib_list.append(fib)
			if N in fib_list:
				return 'Yes'
			else:
				return 'No'


class Solution:

	def checkFibonacci(ob, N):
		if isFibonacci(N):
			return 'Yes'
		return 'No'
import math

def isPerfectSquare(x):
	s = int(math.sqrt(x))
	return s * s == x

def isFibonacci(n):
	return isPerfectSquare(5 * n * n + 4) or isPerfectSquare(5 * n * n - 4)


class Solution:

	def checkFibonacci(ob, N):
		if N < 4:
			return 'Yes'
		(i, j) = (2, 3)
		while i + j < N:
			(i, j) = (j, i + j)
		if i + j == N:
			return 'Yes'
		return 'No'


import math

class Solution:

	def checkFibonacci(ob, n):
		s = 5 * n * n + 4
		s1 = 5 * n * n - 4
		a = int(math.sqrt(s))
		b = int(math.sqrt(s1))
		if a * a == s:
			return 'Yes'
		elif b * b == s1:
			return 'Yes'
		return 'No'


class Solution:

	def checkFibonacci(self, N):
		a = 0
		b = 1
		flag = 0
		while b <= N:
			c = a + b
			a = b
			b = c
			if c == N:
				flag = 1
		if flag == 1:
			return 'Yes'
		else:
			return 'No'


class Solution:

	def checkFibonacci(ob, N):
		x = 0
		y = 1
		l = []
		l.append(x)
		l.append(y)
		for i in range(2, N + 2):
			sum = x + y
			l.append(sum)
			x = y
			y = sum
		if N in l:
			return 'Yes'
		else:
			return 'No'


import math

def isPerfectSquare(x):
	s = int(math.sqrt(x))
	return s * s == x

class Solution:

	def checkFibonacci(ob, n):
		x = isPerfectSquare(5 * n * n + 4) or isPerfectSquare(5 * n * n - 4)
		if x == True:
			return 'Yes'
		else:
			return 'No'


class Solution:

	def checkFibonacci(ob, N):
		a = 1
		b = 1
		arr = []
		num = 1
		if N <= 2:
			return 'Yes'
		else:
			while num < N:
				ans = 'No'
				num = a + b
				if num == N:
					ans = 'Yes'
					return ans
				a = b
				b = num
			if ans == 'No':
				return ans


class Solution:

	def checkFibonacci(ob, N):
		k = [0, 1]
		if k == 0 or k == 1:
			return True
		while k[-1] < N:
			k.append(k[-1] + k[-2])
		if k[-1] == N:
			return 'Yes'
		else:
			return 'No'


class Solution:

	def checkFibonacci(ob, N):
		if N == 0 or N == 1:
			return 'Yes'
		else:
			(a, b) = (0, 1)
			while True:
				c = a + b
				a = b
				b = c
				if c == N:
					return 'Yes'
				elif c > N:
					return 'No'


class Solution:

	def checkFibonacci(ob, N):
		f = 1
		s = 1
		fib = [f, s]
		for i in range(1, 11):
			t = s + f
			fib.append(t)
			s = f
			f = t
		if N in fib:
			return 'Yes'
		else:
			return 'No'


class Solution:

	def checkFibonacci(ob, N):
		(a, b) = (1, 1)
		while a <= 100:
			if N == a:
				return 'Yes'
			(a, b) = (b, a + b)
		return 'No'


class Solution:

	def checkFibonacci(ob, N):
		first_ele = 0
		second_ele = 1
		if N == 0 or N == 1:
			return 'Yes'
		for i in range(N):
			next_ele = first_ele + second_ele
			if next_ele == N:
				return 'Yes'
			first_ele = second_ele
			second_ele = next_ele
		return 'No'


class Solution:

	def checkFibonacci(ob, N):
		arr = [0, 1]
		for i in range(2, N + 2):
			if arr[i - 1] + arr[i - 2] <= N:
				arr.append(arr[i - 1] + arr[i - 2])
			else:
				break
		if arr.__contains__(N):
			return 'Yes'
		else:
			return 'No'


class Solution:

	def checkFibonacci(ob, N):
		(x, y, z) = (0, 1, 1)
		while z <= N:
			if z == N:
				return 'Yes'
			x = y
			y = z
			z = x + y
		return 'No'


class Solution:

	def checkFibonacci(ob, N):
		if N == 1:
			return 'Yes'
		arr = [1, 1]
		i = 2
		while arr[i - 1] < N:
			arr.append(0)
			arr[i] = arr[i - 1] + arr[i - 2]
			if arr[i] == N:
				return 'Yes'
			i = i + 1
		return 'No'


class Solution:

	def checkFibonacci(ob, N):
		a = 0
		b = 1
		sum = a + b
		while True:
			if sum < N:
				sum = a + b
				a = b
				b = sum
			else:
				if sum == N:
					return 'Yes'
				else:
					return 'No'
				break


class Solution:

	def checkFibonacci(ob, N):

		def fibon(n):
			a = 0
			b = 1
			for i in range(n):
				yield a
				(a, b) = (b, a + b)
		x = list(fibon(50))
		if N in x:
			return 'Yes'
		else:
			return 'No'


import math

class Solution:

	def checkFibonacci(ob, N):
		x = math.sqrt(5 * N * N + 4)
		y = math.sqrt(5 * N * N - 4)
		if math.floor(x) == x or math.floor(y) == y:
			return 'Yes'
		else:
			return 'No'


import math

class Solution:

	def checkFibonacci(ob, N):
		if N == 0 or N == 1 or N == 2 or (N == 3) or (N == 5) or (N == 8) or (N == 13) or (N == 21) or (N == 34) or (N == 55) or (N == 89):
			return 'Yes'
		return 'No'
		if N == 3:
			return 'Yes'
		n = N
		cg = 5 * n * n - 4
		print(cg)
		a = math.sqrt(cg)
		print(a)
		a = int(a)
		if cg == a * a:
			return 'Yes'
		return 'No'


class Solution:

	def checkFibonacci(ob, N):
		fib = [1, 1]
		while fib[-1] < N:
			fib.append(fib[-1] + fib[-2])
		return 'Yes' if fib[-1] == N else 'No'


class Solution:

	def checkFibonacci(ob, N):

		def helper(x, prev, cur):
			if cur == x:
				return 'Yes'
			elif cur > x:
				return 'No'
			temp = cur
			cur = cur + prev
			prev = temp
			return helper(x, prev, cur)
		return helper(N, 1, 1)


class Solution:

	def checkFibonacci(ob, num):
		a = 0
		b = 1
		while num > a:
			temp = a
			a = b
			b = temp + b
		if num == a:
			return 'Yes'
		else:
			return 'No'


class Solution:

	def checkFibonacci(ob, N):
		import math
		x = 5 * N * N + 4
		y = 5 * N * N - 4
		if int(x ** 0.5) ** 2 == x or int(y ** 0.5) ** 2 == y:
			return 'Yes'
		else:
			return 'No'


class Solution:

	def checkFibonacci(ob, N):
		if N == 0 or N == 1:
			return 'Yes'
		else:
			f = 0
			a = 0
			b = 1
			c = a + b
			for i in range(2, N + 10):
				a = b
				b = c
				c = a + b
				if c == N:
					f = 1
			if f == 1:
				return 'Yes'
			return 'No'


class Solution:

	def checkFibonacci(ob, N: int) -> str:

		def is_perfect_square(num: int) -> bool:
			x = int(num ** 0.5)
			return x * x == num
		y = 5 * N ** 2 + 4
		z = 5 * N ** 2 - 4
		if is_perfect_square(y) or is_perfect_square(z):
			return 'Yes'
		else:
			return 'No'


import math

class Solution:

	def checkFibonacci(ob, N):
		(a, b) = (5 * N * N + 4, 5 * N * N - 4)
		(x, y) = [int(x) for x in [math.sqrt(a), math.sqrt(b)]]
		if x * x == a or y * y == b:
			return 'Yes'
		return 'No'


from math import sqrt

class Solution:

	def perfectSq(ob, a):
		return int(sqrt(a)) * int(sqrt(a)) == a

	def checkFibonacci(ob, N):
		(a, b) = (5 * N ** 2 + 4, 5 * N ** 2 - 4)
		if ob.perfectSq(a) or ob.perfectSq(b):
			return 'Yes'
		else:
			return 'No'


class Solution:

	def checkFibonacci(ob, n):
		a = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
		if n in a:
			return 'Yes'
		return 'No'


import math

class Solution:

	def check(self, n):
		s = int(math.sqrt(n))
		return s * s == n

	def checkFibonacci(self, n):
		if self.check(5 * n * n + 4) or self.check(5 * n * n - 4):
			return 'Yes'
		return 'No'


class Solution:

	def checkFibonacci(ob, n):
		(a, b) = (0, 1)
		for i in range(100):
			t = a + b
			(a, b) = (b, t)
			if n == t:
				return 'Yes'
		return 'No'


import math

class Solution:

	def checkFibonacci(ob, n):
		a = 5 * (n * n) + 4
		b = 5 * (n * n) - 4
		res = int(a ** 0.5) == a ** 0.5 or int(b ** 0.5) == b ** 0.5
		if res:
			return 'Yes'
		else:
			return 'No'


class Solution:

	def checkFibonacci(ob, N):
		if N <= 1:
			return 'Yes'
		num0 = 0
		num1 = 1
		sum = 0
		while sum <= N:
			if sum == N:
				return 'Yes'
			sum = num0 + num1
			num0 = num1
			num1 = sum
		return 'Yes' if sum == N else 'No'


class Solution:

	def checkFibonacci(ob, N):
		if N == 0 or N == 1:
			return 'Yes'
		a = 0
		b = 1
		for i in range(N):
			c = a + b
			if c == N:
				return 'Yes'
			a = b
			b = c
		return 'No'


class Solution:

	def checkFibonacci(ob, N):
		from math import sqrt
		z_1 = 5 * N * N - 4
		z_2 = 5 * N * N + 4
		if z_1 == int(sqrt(z_1)) ** 2 or z_2 == int(sqrt(z_2)) ** 2:
			return 'Yes'
		return 'No'


class Solution:

	def checkFibonacci(ob, N):
		n1 = 1
		n2 = 1
		if N == n1:
			return 'Yes'
		while n2 <= N:
			if n2 == N:
				return 'Yes'
			x = n2
			n2 = n2 + n1
			n1 = x
		return 'No'


class Solution:

	def checkFibonacci(ob, N):
		if N == 0 and N == 1:
			return 'Yes'
		a1 = 0
		a2 = 1
		for i in range(N):
			nexti = a1 + a2
			if nexti == N:
				return 'Yes'
			a1 = a2
			a2 = nexti
		return 'No'


class Solution:

	def checkFibonacci(ob, N):
		a = 5 * N ** 2 + 4
		b = 5 * N ** 2 - 4
		if int(a ** 0.5) == a ** 0.5:
			return 'Yes'
		elif int(b ** 0.5) == b ** 0.5:
			return 'Yes'
		else:
			return 'No'