Logic help

AIM - To return an integer representing the number of square integers in the inclusive range from A to B .
example - for input 3 9
the output would be 2 as 4 and 9are the two square integers

We can simply take square root of ‘a’ and square root of ‘b’ and count the perfect squares between them using
floor(sqrt(b)) - ceil(sqrt(a)) + 1

can someone explain me the concept .i know putting the inputs the output is right…but wanted to know the LOGIC behind it.

may be its like if we consider numbers 1 to n and the squares of their numbers , if given some
range, (),1,4,9,16,15,36,49
like 10 to 50 ,if we consider the nearest square would be 16 ,and for 50 it would be 49 that is 4 square and 7 square the number of numbers having squares in between them would be 5,6
if we ask it would be 4 numbers

1 Like

okayy