BigInteger getResult(int n, int r) { BigInteger ans; ans = F[n]; ans = ans.divide(F[r]); ans = ans.divide(F[n - r]); return ans; }
public static void num(String str) { BigInteger a = new BigInteger(str); StringBuffer sb = new StringBuffer(""); StringBuffer n = new StringBuffer(""); while (!(a.divide(div).equals(zero))) { sb.insert(0, (char) (a.mod(div).intValue() + 96)); a = a.divide(div); } sb.insert(0, (char) (a.intValue() + 96)); for (int i = 0; i < str.length(); i++) { if (i % 3 == 0 && i != 0) n.insert(0, ","); n.insert(0, str.charAt(str.length() - i - 1)); } while (sb.length() < 22) sb.append(" "); System.out.println(sb + "" + n); }
public static void main(String args[]) throws Exception { Scanner cin = new Scanner(System.in); BigInteger s, M; int p, i; while (cin.hasNext()) { p = cin.nextInt(); s = BigInteger.valueOf(4); M = BigInteger.ONE; M = M.shiftLeft(p).subtract(BigInteger.ONE); for (i = 0; i < p - 2; ++i) { s = s.multiply(s).subtract(BigInteger.valueOf(2)); while (s.bitLength() > p) { s = s.shiftRight(p).add(s.and(M)); } } if (s.compareTo(BigInteger.ZERO) == 0 || s.compareTo(M) == 0) { System.out.println(0); continue; } String ans = ""; while (s.compareTo(BigInteger.ZERO) > 0) { long buf = s.mod(BigInteger.valueOf(16)).longValue(); ans += Integer.toHexString((int) buf); s = s.divide(BigInteger.valueOf(16)); } for (i = ans.length() - 1; i >= 0; --i) System.out.print(ans.charAt(i)); System.out.println(); } }
public static void main(String[] args) { BigInteger a = BigInteger.valueOf(1), // without OO b = 2, // with OO c1 = a.negate().add(b.multiply(b)).add(b.divide(a)), // without OO c2 = -a + b * b + b / a; // with OO if (c1.compareTo(c2) < 0 || c1.compareTo(c2) > 0) System.out.println("impossible"); // without OO if (c1 < c2 || c1 > c2) System.out.println("impossible"); // with OO HashMap<String, String> map = new HashMap<>(); if (!map.containsKey("qwe")) map.put("qwe", "asd"); // without OO if (map["qwe"] == null) map["qwe"] = "asd"; // with OO }
public static boolean check(long n, int p) { BigInteger P = BigInteger.TEN.pow(p), Q = BigInteger.TEN.pow(p - 1); BigInteger N = BigInteger.ONE, tmp = BigInteger.valueOf(2); while (n > 0) { if ((n % 2) == 1) { N = N.multiply(tmp); N = N.mod(P); } tmp = tmp.multiply(tmp); tmp = tmp.mod(P); n >>= 1; } N = N.divide(Q); if (N.equals(BigInteger.ONE) || N.equals(BigInteger.valueOf(2))) return true; else return false; }
public static void main(String[] args) { PrintWriter pw; Scanner sc; try { sc = new Scanner(new File("input.txt")); BigInteger a, b, c; a = sc.nextBigInteger(); b = sc.nextBigInteger(); c = a.divide(b); // System.out.println(firstTeam+" "+secondTeam); pw = new PrintWriter(new File("output.txt")); pw.print(c); pw.close(); } catch (IOException e) { } }
public static void main(String[] args) throws IOException { Scanner scanner = new Scanner(new BufferedInputStream(System.in)); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = 1; while (scanner.hasNextInt()) { int a = scanner.nextInt(); int b = scanner.nextInt(); if (a == 0) break; BigInteger sum = BigInteger.ZERO; BigInteger bb = BigInteger.valueOf(b); for (int i = 0; i < a; i++) sum = sum.add(scanner.nextBigInteger()); System.out.println( "Bill #" + n + " costs " + sum + ": each friend should pay " + sum.divide(bb) + "\n"); n++; } }
public String getKDigits(int N, int K) { BigInteger ret = new BigInteger("1"); BigInteger ten = new BigInteger("10"); for (int i = 1; i <= N; i++) { ret = ret.multiply(new BigInteger(new Integer(i).toString())); } System.out.println(ret); while (ret.mod(ten).equals(BigInteger.ZERO)) ret = ret.divide(ten); String ans = ret.toString(); if (ans.length() > K) { ans = ans.substring(ans.length() - K, ans.length()); } return ans; }
public static void main(String[] args) throws IOException { Scanner scanner = new Scanner(new BufferedInputStream(System.in)); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); while (scanner.hasNextInt()) { int n = scanner.nextInt(); int k = scanner.nextInt(); BigInteger sum = BigInteger.ONE; for (int i = n; i > n - k; i--) { sum = sum.multiply(BigInteger.valueOf(i)); } for (int i = 2; i <= k; i++) { sum = sum.divide(BigInteger.valueOf(i)); } System.out.println(sum.toString().length()); } }