Skip to content

Instantly share code, notes, and snippets.

@Kenji-H
Last active December 16, 2015 17:48
Show Gist options
  • Save Kenji-H/5472774 to your computer and use it in GitHub Desktop.
Save Kenji-H/5472774 to your computer and use it in GitHub Desktop.
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.math.BigInteger.*;
import java.io.*;
import java.util.*;
@SuppressWarnings("unused")
public class A {
Scanner sc = new Scanner(System.in);
void solve() {
long r = sc.nextLong();
long t = sc.nextLong();
long lo = 1;
long hi = (long) 1e9 + 10;
while (hi - lo > 1) {
long x = (lo + hi) / 2;
if (2.0 * x * x + (2.0 * r - 1) * x > 1.1 * t)
hi = x;
else if (2 * x * x + (2 * r - 1) * x > t)
hi = x;
else
lo = x;
}
System.out.println(lo);
}
void run() {
int caseN = sc.nextInt();
for (int caseID = 1; caseID <= caseN; caseID++) {
System.out.printf("Case #%d: ", caseID);
System.err.printf("Solving Case #%d...\n", caseID);
solve();
System.out.flush();
}
}
void debug(Object... os) {
System.err.println(deepToString(os));
}
public static void main(String[] args) {
new A().run();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment