You are viewing a single comment's thread. Return to all comments →
From my HackerRank solutions.
Simply count # of integers (inclusive) between the square roots of A and B
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int T = scan.nextInt(); while (T-- > 0) { int A = scan.nextInt(); int B = scan.nextInt(); int numSquares = (int) (Math.floor(Math.sqrt(B)) - Math.ceil(Math.sqrt(A)) + 1); System.out.println(numSquares); } scan.close(); } }
Let me know if you have any questions.
Seems like cookies are disabled on this browser, please enable them to open this website
Sherlock and Squares
You are viewing a single comment's thread. Return to all comments →
Java solution - passes 100% of test cases
From my HackerRank solutions.
Simply count # of integers (inclusive) between the square roots of A and B
Let me know if you have any questions.