Sherlock and Squares

Sherlock and Squares


Watson gives two integers ( and ) to Sherlock and asks if he can count the number of square integers between  and  (both inclusive).
Note: A square integer is an integer which is the square of any integer. For example, 149, and 16 are some of the square integers as they are squares of 123, and 4, respectively.
Input Format
The first line contains , the number of test cases.  test cases follow, each in a new line. 
Each test case contains two space-separated integers denoting  and .
--Solution--
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    int t,i,l;
   unsigned int x,y,j,k;
   cin>>t; 
    for(i=0;i<t;i++)
        {cin>>x>>y;l=0;
        for(j=1;j<=y;j++)
            {
              k=j*j;
            if(k>=x && k<=y)
                l++;
            if(k>=y)
                break;
        }cout<<l<<endl;
        } 
    return 0;
}

Comments

Popular posts from this blog

Cut the sticks