public BigInteger count(int n) { BigInteger[] prev = new BigInteger[k]; Arrays.fill(prev, BigInteger.ZERO); prev[s] = BigInteger.ONE; while (n-- > 0) { BigInteger[] next = new BigInteger[k]; Arrays.fill(next, BigInteger.ZERO); for (int i = 0; i < k; ++i) { if (prev[i].signum() <= 0) { continue; } for (int j = 0; j < z; ++j) { if (e[j][i] < 0) { continue; } next[e[j][i]] = next[e[j][i]].add(prev[i]); } } prev = next; } BigInteger ans = BigInteger.ZERO; for (int term : t) { ans = ans.add(prev[term]); } return ans; }
public static BigInteger largeSum(ArrayList<BigInteger> nums) { BigInteger sum = BigInteger.ZERO; for (BigInteger i : nums) { sum = sum.add(i); } return sum; }
public static void countPairs(Integer[] arr) { HashMap<Integer, Integer> seenElements = new HashMap<Integer, Integer>(); // ArrayList<Integer> countList = new ArrayList<Integer for (int i = 0; i < arr.length; i++) { if (!seenElements.containsKey(arr[i])) { seenElements.put(arr[i], 1); } else { seenElements.put(arr[i], seenElements.get(arr[i]) + 1); } } BigInteger count = null; for (int element : seenElements.keySet()) { if (seenElements.get(element) > 1) { System.out.println("count is :" + seenElements.get(element)); count.add( factorial(seenElements.get(element)).divide(factorial(seenElements.get(element) - 2))); System.out.println(count); } } if (count == null) { System.out.println("0"); } }
public static void main(String[] args) { Scanner s = new Scanner(System.in); BigInteger a = new BigInteger(s.next()); BigInteger b = new BigInteger(s.next()); BigInteger ad = a.add(b); BigInteger mu = a.multiply(b); System.out.println(ad); System.out.println(mu); }
public static void main(String[] args) { /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ Scanner scan = new Scanner(System.in); BigInteger bigInteger1 = scan.nextBigInteger(); BigInteger bigInteger2 = scan.nextBigInteger(); System.out.println(bigInteger1.add(bigInteger2)); System.out.println(bigInteger1.multiply(bigInteger2)); }
public static void process() { Arrays.sort(bookHeight); BigInteger sum = BigInteger.valueOf(0L); BigInteger temp; int iCount = 0; for (int i = bookHeight.length - 1; i >= 0; i--) { sum = sum.add(BigInteger.valueOf((long) (bookHeight[i]))); temp = sum.max(b); iCount++; if (temp.equals(sum)) break; } System.out.print(iCount); }
public static void main(String[] args) throws Exception { BigInteger T = BigInteger.valueOf(0); BigInteger TB = BigInteger.valueOf(0); BigInteger NTB = BigInteger.valueOf(0); BigInteger S = BigInteger.valueOf(0); BigInteger MAX = BigInteger.valueOf(1); int j; for (j = 0; j < 100; j++) MAX = MAX.multiply(BigInteger.valueOf(10)); for (; ; ) { int i, t, a, b; if (in.nextToken() != StreamTokenizer.TT_NUMBER) break; t = (int) in.nval; if (in.nextToken() != StreamTokenizer.TT_NUMBER) break; a = (int) in.nval; if (in.nextToken() != StreamTokenizer.TT_NUMBER) break; b = (int) in.nval; // System.out.print("("); // System.out.print(t); // System.out.print("^"); // System.out.print(a); // System.out.print("-1)/("); // System.out.print(t); // System.out.print("^"); // System.out.print(b); // System.out.print("-1) "); if (t == 1 || a % b != 0) { System.out.print("bad!\n"); continue; } T = BigInteger.valueOf(t); TB = BigInteger.valueOf(1); for (i = 0; i < b; i++) { TB = TB.multiply(T); if (TB.compareTo(MAX) >= 0) break; } NTB = BigInteger.valueOf(1); S = BigInteger.valueOf(0); for (i = 0; i < a; i += b) { S = S.add(NTB); if (S.compareTo(MAX) >= 0) break; NTB = NTB.multiply(TB); } if (S.compareTo(MAX) >= 0) System.out.print("bad!"); else System.out.print(S); System.out.print("\n"); } }
public static void abcd(String str) { BigInteger sum = BigInteger.ZERO; StringBuffer n = new StringBuffer(""); for (int i = 0; i < str.length(); i++) { BigInteger ab = BigInteger.valueOf(((int) str.charAt(i)) - 96); sum = sum.add(div.pow(str.length() - i - 1).multiply(ab)); } String s = sum.toString(); for (int i = 0; i < s.length(); i++) { if (i % 3 == 0 && i != 0) n.insert(0, ","); n.insert(0, s.charAt(s.length() - i - 1)); } while (str.length() < 22) str = str + " "; System.out.println(str + "" + n); }
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 void DP() { for (int i = 0; i <= m; i++) { for (int j = 0; j <= sz; j++) { dp[i][j] = BigInteger.ZERO; } } dp[0][0] = BigInteger.ONE; for (int i = 0; i < m; i++) { for (int j = 0; j < sz; j++) if (dp[i][j].compareTo(BigInteger.valueOf(0)) == 1) { for (int k = 0; k < CD; k++) { if (flag[ch[j][k]] > 0 || flag[j] > 0) continue; dp[i + 1][ch[j][k]] = dp[i + 1][ch[j][k]].add(dp[i][j]); } } } ans = BigInteger.ZERO; for (int i = 0; i < sz; i++) ans = ans.add(dp[m][i]); out.println(ans); }
/** @param args the command line arguments */ public static void main(String[] args) { // Takes user input and converts into a character array Scanner sc = new Scanner(System.in); int n = Integer.parseInt(sc.nextLine()); String input = sc.nextLine(); String[] a = input.split(" "); BigInteger[] storage = new BigInteger[n]; BigInteger sum = new BigInteger("0"); // Converts and Stores Big Integers for (int i = 0; i < n; i++) storage[i] = new BigInteger(a[i]); // Sums the BigIntegers in storage for (int j = 0; j < n; j++) sum = sum.add(storage[j]); // Outputs the sum of values in storage as a string System.out.println(sum); }