Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- import java.math.*;
- public class Main {
- static BufferedReader in;
- static StringTokenizer strtok;
- static String next() throws IOException {
- while (strtok == null || !strtok.hasMoreTokens())
- strtok = new StringTokenizer(in.readLine());
- return strtok.nextToken();
- }
- static int nextInt() throws IOException {
- return Integer.parseInt(next());
- }
- static long nextLong() throws IOException {
- return Long.parseLong(next());
- }
- static double nextDouble() throws IOException {
- return Double.parseDouble(next());
- }
- static long a, b, c;
- static BigInteger sum2(long n) {
- --n;
- return BigInteger.valueOf(n).multiply(BigInteger.valueOf(n + 1)).multiply(BigInteger.valueOf(2 * n + 1)).divide(BigInteger.valueOf(6));
- }
- static BigInteger sum(long n) {
- return BigInteger.valueOf(n - 1).multiply(BigInteger.valueOf(n)).divide(BigInteger.valueOf(2));
- }
- static boolean Ok(long n) {
- BigInteger va = BigInteger.valueOf(a);
- BigInteger vb = BigInteger.valueOf(b);
- BigInteger vc = BigInteger.valueOf(c);
- BigInteger vn = BigInteger.valueOf(n);
- BigInteger A, B, C;
- A = vn.multiply(va);
- B = vn.multiply(vb).add(va.multiply(BigInteger.valueOf(2).multiply(sum(n))));
- C = va.multiply(sum2(n)).add(vb.multiply(sum(n))).add(vn.multiply(vc));
- return B.multiply(B).subtract(BigInteger.valueOf(4).multiply(A).multiply(C)).compareTo(BigInteger.ZERO) < 0;
- }
- public static void main(String args[]) throws IOException {
- in = new BufferedReader(new InputStreamReader(System.in));
- PrintWriter out = new PrintWriter(System.out);
- int tests = nextInt();
- for (int test = 1; test <= tests; ++test) {
- a = nextLong();
- b = nextLong();
- c = nextLong();
- long le = 0, ri = (long)1e18;
- while (ri - le > 1) {
- long mid = (le + ri) / 2;
- if (Ok(mid)) ri = mid; else
- le = mid;
- }
- if (!Ok(ri)) out.println("Infinity"); else
- out.println(ri);
- }
- out.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement