Topic:
Watson gave Sherlock two integers a and _b_, and now Watson asks Sherlock if he can calculate the number of complete squares between A and _b_ (including A and B). The total square number refers to the square of any integer. For example,1, 4, 9, 16 is the complete square number, because they are 1, 2,3 1≤t≤100 1≤a≤b≤109 input Sample 917 Output Sample In a set of test data, 4 and 9 are full squares. In the second set of test data, between 17 and 24 (inclusive of 17 and 24), there is no complete square.
Analysis: The main application of the floor () and ceil () two functions in math, the Java code is as follows:
Public Static intSquaresnums (intAintb) {return(int) (Math.floor (math.sqrt (b))-Math.ceil (Math.sqrt (a))) +1; } Public Static voidMain (string[] args) {/*Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */Scanner in=NewScanner (system.in); intt =In.nextint (); for(inta0 = 0; A0 < T; a0++){ intA =In.nextint (); intb =In.nextint (); System.out.println (Squaresnums (A, b)); } }
Sherlock and Squares