@@ -0,0 +1,1414 @@
+//https://www.hackerrank.com/challenges/sherlock-and-counting%0Aimport java.io.*;%0A%0Apublic class Solution %7B%0A%0A    public static void main(String%5B%5D args) throws IOException %7B%0A        final StringBuffer sb = new StringBuffer();%0A        %0A        //INPUT%0A        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));%0A        for(int T = Integer.parseInt(br.readLine()); T %3E 0; --T)%7B%0A            String%5B%5D input = br.readLine().split(%22 %22);%0A            final int N = Integer.parseInt(input%5B0%5D);%0A            final int K = Integer.parseInt(input%5B1%5D);%0A            %0A            //SOLVE%0A            final long max = 1L * N * K;%0A            final long maxPos = (N %3E%3E 1L)*((N+1L) %3E%3E 1L);%0A            if (maxPos %3C= max)%7B%0A                final int count = ((N %3E%3E 1) %3C%3C 1) - ((N-1) & 1);%0A                sb.append(count + %22%5Cn%22);%0A                continue;%0A            %7D%0A            %0A            final long X = maxPos - max;%0A            final int Y = (((N-1) & 1) == 0) ? (int)Math.ceil(Math.sqrt(X + 0.25) - 0.5) : (int)Math.ceil(Math.sqrt(X + 1) - 1);%0A            final int I = (N %3E%3E 1) - Y;%0A            final int count = (1L*I*(N-I) %3E max) ? (I-1) %3C%3C 1 : I %3C%3C 1;%0A            %0A            //DEBUG%0A            //sb.append(%22X: %22 + X + %22, Y: %22 + Y + %22, I: %22 + I + %22, COUNT: %22 + count + %22%5Cn%22);%0A            %0A            //OUTPUT%0A            sb.append(count + %22%5Cn%22);%0A        %7D%0A        System.out.print(sb);%0A    %7D%0A%7D%0A

Create sherlock-and-counting.java