Hello Programmers, In this post, you will know how to solve the HackerRank Sherlock and Squares Solution. This problem is a part of the HackerRank Algorithms Series.HackerRank Sherlock and Squares SolutionOne more thing to add, don’t directly look for the solutions, first try to solve the problems of Hackerrank by yourself. If you find any difficulty after trying several times, then you can look for solutions.HackerRank Sherlock and Squares SolutionTaskWatson likes to challenge Sherlock’s math ability. He will provide a starting and ending value that describe a range of integers, inclusive of the endpoints. Sherlock must determine the number of square integers within that range.Note: A square integer is an integer which is the square of an integer, e.g. 1, 4, 9, 16, 25.Examplea = 24b = 49There are three square integers in the range: 25, 36 and 49. Return 3.Function DescriptionComplete the squares function in the editor below. It should return an integer representing the number of square integers in the inclusive range from a to b.squares has the following parameter(s):int a: the lower range boundaryint b: the upper range boundaryReturnsint: the number of square integers in the rangeInput FormatThe first line contains q, the number of test cases.Each of the next q lines contains two space-separated integers, a and b, the starting and ending integers in the ranges.Constraints1 <= q <= 1001 <= a <= b <= 109Sample Input23 917 24Sample Output20ExplanationTest Case #00: In range [3, 9], 4 and 9 are the two square integers.Test Case #01: In range [17, 24], there are no square integers.HackerRank Sherlock and Squares SolutionSherlock and Squares Solution in C#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> int main() { int t; int a,b,sa,sb; scanf("%d",&t); while(t--) { scanf("%d %d",&a,&b); sa = sqrt(a), sb = sqrt(b); if(sa*sa == a)sa--; printf("%d\n",sb - sa); } /* Enter your code here. Read input from STDIN. Print output to STDOUT */ return 0; }Sherlock and Squares Solution in Cpp#include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> using namespace std; int main() { int n,m; cin>>n; while (cin>>n>>m) { cout<<(int)(sqrt(m)+0.0000001)-(int)(sqrt(n-1)+0.0000001)<<endl; } return 0; }Sherlock and Squares Solution in Java//package contest; import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static void main(String[] args) { /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); try{ String line = br.readLine(); int num = Integer.parseInt(line); for(int i = 0; i < num; i++){ String[] inp = br.readLine().split(" "); int a = Integer.parseInt(inp[0]); int b = Integer.parseInt(inp[1]); int count = 0; for(int j = 1; j*j <= b; j++){ if(j*j >= a){ count++; } } System.out.println(count); } } catch(Exception e) { } } }Sherlock and Squares Solution in Pythonfrom math import sqrt T = int(input()) for i in range(T): count = 0 inp = [int(a) for a in input().split()] c = inp[0] while int(sqrt(c)) != sqrt(c) and c<inp[1]: c+=1 while c <= inp[1] and int(sqrt(c)) == sqrt(c): count += 1 c += 2*sqrt(c)+1 print(count)Sherlock and Squares Solution using JavaScriptfunction processData(input) { lines = input.trim().split("\n"); for(var i=1;i<lines.length && lines[i].length > 0;i++){ start = parseInt(lines[i].trim().split(" ")[0]); end = parseInt(lines[i].trim().split(" ")[1]); squares =0; min = Math.sqrt(start); if(min != Math.floor(min)){ min = Math.floor(min) + 1; } max = Math.sqrt(end); if(max != Math.floor(max)){ max = Math.floor(max); } if(max < min){ console.log("0"); } else { console.log((max-min+1)); } } } process.stdin.resume(); process.stdin.setEncoding("ascii"); _input = ""; process.stdin.on("data", function (input) { _input += input; }); process.stdin.on("end", function () { processData(_input); });Sherlock and Squares Solution in Scalaobject Solution { def main(args: Array[String]) { val t = readLine.toInt; for(i <- 1 to t) println(f(readLine.split(" "))); } def f(n:Array[String]):Long = { return Math.sqrt(n(1).toInt).toLong - Math.sqrt(n(0).toInt-1).toLong; } }Sherlock and Squares Solution in Pascalprogram PSherlockandSquares; Uses math; var T,A,B,i:Longint; begin ReadLn(T); for i:=1 to T do begin Read(A); ReadLn(B); WriteLn(floor(sqrt(B))-ceil(sqrt(A))+1); end; end.Disclaimer: This problem (Sherlock and Squares) is generated by HackerRank but the Solution is Provided by BrokenProgrammers. This tutorial is only for Educational and Learning purposes.Next: HackerRank Jumping on the Clouds: Revisited Solution Post navigationHackerRank Find Digits Solution HackerRank Jumping on the Clouds: Revisited Solution