Given two given numbers a and b where 1<=a<=b, find the number of perfect squares between a and b (a and b inclusive).
 
Example 1:
Input:
a = 9, b = 25
Output:
3
Explanation:
There are 3 perfect squares between 9
and 25. They are 9, 16, and 25.
Example 2:
Input:
a = 1, b = 7
Output:
2
Explanation:
There are 2 perfect squares between 1
and 7. They are 1, and 4.
 
Your Task:
You don't need to read input or print anything. Your task is to complete the function numOfPerfectSquares() which takes 2 Integers a and b as input and returns the number of perfect squares between a and b.
 
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
 
Constraints:
1 <= a <= b <= 10^{5}

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3

class Solution:
    def numOfPerfectSquares(self, a, b):
        # code here

Solutions:
class Solution:

	def numOfPerfectSquares(self, a, b):
		sum = 0
		c = int(b ** 0.5) + 1
		for i in range(1, c):
			if i ** 2 >= a and i ** 2 <= b:
				sum += 1
			else:
				continue
		return sum


class Solution:

	def numOfPerfectSquares(self, a, b):
		a = math.sqrt(a)
		b = math.sqrt(b)
		if a == int(a) or b == int(b):
			return int(b - a) + 1
		elif a == int(a) and b == int(b):
			return int(b) - int(a) + 1
		else:
			return int(b) - int(a)


from math import *

class Solution:

	def numOfPerfectSquares(self, a, b):
		num = ceil(sqrt(a))
		count = 0
		while pow(num, 2) <= b:
			count += 1
			num += 1
		return count


class Solution:

	def numOfPerfectSquares(self, a, b):
		c = int(a ** 0.5)
		d = int(b ** 0.5)
		c = 0
		for i in range(c, d + 1):
			if i ** 2 >= a:
				if i ** 2 <= b:
					c += 1
		return c


class Solution:

	def numOfPerfectSquares(self, a, b):
		sum = 0
		for x in range(1, 200):
			d = x * x
			if d <= b and d >= a:
				sum = sum + 1
		return sum


import math

class Solution:

	def numOfPerfectSquares(self, a, b):
		count_b = math.floor(math.sqrt(b))
		count_a = math.floor(math.sqrt(a - 1))
		return count_b - count_a


class Solution:

	def numOfPerfectSquares(self, a, b):
		return math.floor(math.sqrt(b)) - math.ceil(math.sqrt(a)) + 1


import math

class Solution:

	def numOfPerfectSquares(self, a, b):
		x = math.sqrt(a)
		if x == int(x):
			return int(math.sqrt(b)) - int(math.sqrt(a)) + 1
		else:
			return int(math.sqrt(b)) - int(math.sqrt(a))


import math

class Solution:

	def numOfPerfectSquares(self, a, b):
		num1 = math.ceil(math.sqrt(a))
		num2 = math.floor(math.sqrt(b))
		return num2 - num1 + 1


class Solution:

	def numOfPerfectSquares(self, a, b):
		x = int(a ** 0.5)
		y = int(b ** 0.5)
		if x != a ** 0.5:
			x += 1
		return y - x + 1


import math

class Solution:

	def numOfPerfectSquares(self, a, b):
		x = math.ceil(math.sqrt(a))
		y = math.sqrt(b)
		x1 = int(x)
		y1 = int(y)
		return y1 - x1 + 1


class Solution:

	def numOfPerfectSquares(self, a, b):
		i = 1
		K = []
		while i * i <= b:
			if i * i >= a:
				K.append(i * i)
			i += 1
		return len(K)


from math import sqrt

class Solution:

	def numOfPerfectSquares(self, a, b):
		count = 0
		for i in range(int(sqrt(a)), int(sqrt(b) + 1)):
			if i * i >= a and i * i <= b:
				count += 1
		return count


class Solution:

	def numOfPerfectSquares(self, a: int, b: int) -> int:

		def isPerfectSquare(num: int) -> bool:
			z = int(num ** 0.5)
			return z * z == num
		x = int(b ** 0.5)
		y = int(a ** 0.5)
		if isPerfectSquare(a):
			return x - y + 1
		else:
			return x - y


from math import sqrt

class Solution:

	def numOfPerfectSquares(self, a, b):
		if a > b:
			(a, b) = (b, a)
		a = int(sqrt(a)) if int(sqrt(a)) * int(sqrt(a)) == a else int(sqrt(a) + 1)
		b = int(sqrt(b)) + 1
		return abs(b - a)


class Solution:

	def numOfPerfectSquares(self, a, b):
		import math
		self.a = a
		self.b = b
		p = math.sqrt(a)
		q = math.sqrt(b)
		p = math.floor(q) - math.ceil(p) + 1
		return p


class Solution:

	def numOfPerfectSquares(self, a, b):
		count = 0
		x = math.sqrt(a)
		y = int(math.sqrt(b))
		if x != int(x):
			x = int(x) + 1
		count = int(y) - int(x) + 1
		return count


import math

class Solution:

	def numOfPerfectSquares(self, a, b):
		x = math.sqrt(a)
		y = int(math.sqrt(b))
		if x != int(x):
			x = int(x) + 1
		z = y - int(x) + 1
		return z


import math

class Solution:

	def numOfPerfectSquares(self, a, b):
		return int(math.sqrt(b)) - math.ceil(math.sqrt(a)) + 1


import math

class Solution:

	def numOfPerfectSquares(self, a, b):
		x = int(math.sqrt(a))
		y = int(math.sqrt(b))
		count = 0
		for i in range(x, y + 1):
			z = i * i
			if z >= a and z <= b:
				count += 1
		return count


class Solution:

	def numOfPerfectSquares(self, a, b):
		i = 1
		c = 0
		while i <= math.floor(math.sqrt(b)):
			if i * i >= a and i * i <= b:
				c += 1
			i += 1
		return c


class Solution:

	def numOfPerfectSquares(self, a, b):
		x = int(a ** 0.5)
		y = int(b ** 0.5)
		count = 0
		for i in range(x, y + 1):
			if i ** 2 >= a and i ** 2 <= b:
				count += 1
		return count


import math

class Solution:

	def numOfPerfectSquares(self, a, b):
		sa = math.sqrt(a)
		sb = math.sqrt(b)
		if sa % 1 != 0:
			sa = int(sa) + 1
		if sb % 1 != 0:
			sb = int(sb)
		return int(sb - sa + 1)


from math import *

class Solution:

	def numOfPerfectSquares(self, a, b):
		count = 0
		for i in range(ceil(sqrt(a)), floor(sqrt(b)) + 1):
			count += 1
		return count


class Solution:
	import math

	def numOfPerfectSquares(self, a, b):
		return math.floor(b ** 0.5) - math.ceil(a ** 0.5) + 1


class Solution:

	def numOfPerfectSquares(self, a, b):
		t1 = math.ceil(math.sqrt(a)) - 1
		t2 = math.sqrt(b) if math.sqrt(b) == int(math.sqrt(b)) else math.ceil(math.sqrt(b)) - 1
		return int(t2 - t1)


class Solution:

	def numOfPerfectSquares(self, a, b):
		count = 0
		for i in range(1, b + 1):
			ans = i * i
			if (ans >= a) & (ans <= b):
				count += 1
			elif ans >= b:
				break
		return count


import math

class Solution:

	def numOfPerfectSquares(self, a, b):
		x = math.ceil(a ** 0.5)
		b = int(b ** 0.5)
		return b - x + 1


from math import sqrt, floor, ceil

class Solution:

	def numOfPerfectSquares(self, a, b):
		A = ceil(sqrt(a))
		B = floor(sqrt(b))
		return B - A + 1
import math
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(a, b) = map(int, input().split())
		ob = Solution()
		print(ob.numOfPerfectSquares(a, b))


class Solution:

	def numOfPerfectSquares(self, a, b):
		a1 = int(a ** 0.5)
		b1 = int(b ** 0.5)
		if a1 * a1 == a:
			return b1 - a1 + 1
		return b1 - a1
import math
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(a, b) = map(int, input().split())
		ob = Solution()
		print(ob.numOfPerfectSquares(a, b))


import math

class Solution:

	def numOfPerfectSquares(self, a, b):
		c = int(a ** 0.5)
		d = int(b ** 0.5)
		x = 0
		for i in range(c, d + 1):
			if i * i >= a and i * i <= b:
				x += 1
		return x
import math
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(a, b) = map(int, input().split())
		ob = Solution()
		print(ob.numOfPerfectSquares(a, b))


class Solution:

	def numOfPerfectSquares(self, a, b):
		count = 0
		for i in range(1, b + 1):
			ans = i * i
			if (ans >= a) & (ans <= b):
				count += 1
			elif ans >= b:
				break
		return count
import math
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(a, b) = map(int, input().split())
		ob = Solution()
		print(ob.numOfPerfectSquares(a, b))


class Solution:

	def floor_sqrt(self, N):
		start = 1
		end = N
		ans = 1
		while start <= end:
			mid = (start + end) // 2
			if mid * mid <= N:
				ans = mid
				start = mid + 1
			else:
				end = mid - 1
		return ans

	def ceil_sqrt(self, N):
		start = 1
		end = N
		ans = 1
		while start <= end:
			mid = (start + end) // 2
			if mid * mid >= N:
				ans = mid
				end = mid - 1
			else:
				start = mid + 1
		return ans

	def numOfPerfectSquares(self, a, b):
		ans = self.floor_sqrt(b) - self.ceil_sqrt(a) + 1
		return ans
import math
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(a, b) = map(int, input().split())
		ob = Solution()
		print(ob.numOfPerfectSquares(a, b))


import math

class Solution:

	def numOfPerfectSquares(self, a, b):
		lower_sqrt = math.sqrt(a)
		upper_sqrt = math.sqrt(b)
		lower = math.ceil(lower_sqrt)
		upper = math.floor(upper_sqrt)
		return upper - lower + 1


import math

class Solution:

	def numOfPerfectSquares(self, a, b):
		sq1 = int(math.sqrt(a))
		sq2 = int(math.sqrt(b))
		if sq1 * sq1 == a and sq2 ** sq2 == b:
			return sq2 - sq1 + 1
		if sq1 * sq1 == a:
			return sq2 - sq1 + 1
		else:
			return sq2 - sq1


from math import ceil, floor

class Solution:

	def numOfPerfectSquares(self, a, b):
		count = 0
		n1 = int(a ** (1 / 2))
		n2 = int(b ** (1 / 2))
		for i in range(n1, n2 + 1):
			if i * i <= b and i * i >= a:
				count += 1
		return count


class Solution:

	def numOfPerfectSquares(self, a, b):
		count = 0
		s1 = int(pow(a, 0.5))
		s2 = int(pow(b, 0.5))
		for i in range(s1, s2 + 1):
			if i * i >= a and i * i <= b:
				count += 1
		return count


import math

class Solution:

	def numOfPerfectSquares(self, a, b):
		sqra = int(math.sqrt(a))
		sqrb = int(math.sqrt(b))
		if a == sqra * sqra:
			sqrb += 1
		return sqrb - sqra


class Solution:

	def numOfPerfectSquares(self, a, b):
		m1 = math.sqrt(a)
		m2 = math.sqrt(b)
		if int(m1) * int(m1) == a or int(m2) * int(m2) == b:
			return int(abs(m2 - m1 + 1))
		return abs(int(m2) - int(m1))


import math

class Solution:

	def numOfPerfectSquares(self, a, b):
		a1 = int(math.sqrt(a))
		b1 = int(math.sqrt(b))
		x = [a1]
		if a == a1 * a1:
			return b1 - a1 + 1
		else:
			return b1 - a1
		return len(x)


class Solution:

	def numOfPerfectSquares(self, a, b):
		return int(int(b ** 0.5) - a ** 0.5 + 1)


import math

class Solution:

	def numOfPerfectSquares(self, a, b):
		k = 0
		t = int(math.sqrt(a))
		t1 = int(math.sqrt(b))
		for i in range(t, t1 + 1):
			if i ** 2 <= b and i ** 2 >= a:
				k += 1
		return k


class Solution:

	def numOfPerfectSquares(self, a, b):
		c = 0
		for i in range(int(pow(a, 0.5)), int(pow(b, 0.5) + 1)):
			if i * i >= a and i * i <= b:
				c = c + 1
		return c


import math

class Solution:

	def numOfPerfectSquares(self, a, b):
		f = math.ceil(math.sqrt(a))
		l = math.floor(math.sqrt(b))
		return l - f + 1