-
Notifications
You must be signed in to change notification settings - Fork 694
/
Copy pathSolution.java
30 lines (22 loc) · 1.06 KB
/
Solution.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//Problem: https://www.hackerrank.com/challenges/sherlock-and-squares
//Java 8
import java.io.*;
import java.util.*;
import java.lang.Math;
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. */
Scanner input = new Scanner(System.in);
int T = input.nextInt();
for(int i = 0; i < T; i++)
{
int A = input.nextInt();
int B = input.nextInt();
int start = (int) Math.sqrt(A); //Finds our starting squareInteger
int end = (int) Math.sqrt(B); //Finds our ending squareInteger
int squareIntegers = end-start; //Calculates the squareIntegers between them
squareIntegers += (Math.pow(start,2) >= A) ? 1 : 0; //Checks to make sure we didn't forget one when we floored A
System.out.println(squareIntegers);
}
}
}