Sherlock and Squares : HackerRank Solution

Watson gives two integers (A and B) to Sherlock and asks if he can count the number of square integers between A and B(both inclusive)

Note: A square integer is an integer which is the square of any integer. For example, 1, 4, 9, and 16 are some of the square integers as they are squares of 1, 2, 3 and 4, respectively.



Input:

2

3 9
17 24

Output:


2

0

Explanation:


In the range 3,9 there are two square numbers which are 4 & 9

In the range 17, 24 there are no square numbers

Implementation:


#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() {

    int t;
    float a,b;
    scanf("%d",&t);
    while(t--)
        {
        scanf("%f %f",&a,&b);
        a=ceil(sqrt(a));
        b=floor(sqrt(b));
        printf("%d\n",(((int)(b-a))+1));
    }
    return 0;
}