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 List range(BigInteger start, BigInteger end) { List l = new List(); long st = start.longValue(); long en = start.longValue(); if (BigInteger.valueOf(st).equals(start) && BigInteger.valueOf(en).equals(end)) { int dir = st < en ? 1 : -1; while (st != en) { l.add(BigInteger.valueOf(st)); st = st + dir; } } else { BigInteger dir; if (start.compareTo(end) < 0) { dir = BigInteger.ONE; } else { dir = BigInteger.valueOf(-1); } while (!start.equals(end)) { l.add(start); start = start.add(dir); } } return l; }
public static void main(String[] z) { BigInteger b = BigInteger.ONE; int i = 2, n = new java.util.Scanner(System.in).nextInt(); for (; i < 1501; i++) b = b.multiply(new BigInteger(String.valueOf(i))); System.out.println(b.add(new BigInteger("2"))); for (i = 0; i < n; i++) System.out.println(i + 2); }
public String toString(byte[] bytes) { BigInteger mantissa = ZERO; for (int blockoffset = 8; blockoffset >= 0; blockoffset -= 4) { for (int byteidx = 0; byteidx < 4; byteidx++) { mantissa = mantissa.multiply(BYTESHIFT_FACTOR); int idx = blockoffset + byteidx; mantissa = mantissa.add(new BigInteger(String.valueOf(bytes[idx] & 0xff), 10)); } } // The exponent is stored negative by .NET so we change it back here !!! int exponent = -bytes[13] & 0x1f; boolean negative = bytes[12] != 0; BigDecimal result = new BigDecimal(mantissa); if (exponent < 0) { for (int i = exponent; i < 0; i++) { result = result.divide(TEN, BigDecimal.ROUND_HALF_DOWN); } } else { for (int i = 0; i < exponent; i++) { result = result.multiply(TEN); } } if (negative) { result = result.negate(); } return result.toString(); }
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"); } }
/** @param args */ public static void main(String[] args) { // array: 99*99 = 9801; BigInteger[] array = new BigInteger[9801]; int cont = 0; for (int i = 2; i < 101; i++) { BigInteger dos = new BigInteger("2"); BigInteger uno = new BigInteger("1"); for (int j = 2; j < 101; j++) { array[cont] = dos.pow(i); cont++; dos = dos.add(uno); } } for (int x = 0; x < array.length; x++) { for (int j = 1; j + x < array.length; j++) { int res = array[x].compareTo(array[x + j]); if (res == 0) { cont--; System.out.println("salto!"); break; } } } System.out.println(cont); }
public static void main(String[] args) { Scanner in = new Scanner(System.in); n = in.nextInt(); l = new BigInteger(in.next()); k = in.nextInt(); m = in.nextInt(); BigInteger w = BigInteger.TEN.pow(m); for (int i = 0; i <= n; ++i) a[i] = new BigInteger(in.next()); for (int i = 0; i < Math.min(k, n + 1); ++i) { t = a[0]; for (int j = 1; j <= n; ++j) { t = t.multiply(l); t = t.add(a[j]); } t = t.mod(w); q[n][i] = t.mod(w); int ret = 0; c = t.toString().toCharArray(); int ll = c.length; for (int j = 0; j < Math.min(m, ll); ++j) { ret += (c[ll - 1 - j] - '0') * (c[ll - 1 - j] - '0'); } System.out.println(ret); l = l.add(BigInteger.ONE); } if (k > n) { for (int i = n - 1; i >= 0; --i) { for (int j = 0; j <= i; j++) q[i][j] = q[i + 1][j + 1].subtract(q[i + 1][j]).mod(w); } for (int i = 1; i <= n; ++i) q[0][i] = q[0][0]; int po = 1; for (int i = n + 1; i < k; ++i) { for (int j = 1; j <= n; ++j) q[j][(po + j) % (n + 1)] = q[j - 1][(po + j - 1) % (n + 1)].add(q[j][(po + j - 1) % (n + 1)]).mod(w); int ret = 0; c = q[n][(po + n) % (n + 1)].mod(w).toString().toCharArray(); int ll = c.length; for (int j = 0; j < Math.min(m, ll); ++j) { ret += (c[ll - 1 - j] - '0') * (c[ll - 1 - j] - '0'); } System.out.println(ret); l = l.add(BigInteger.ONE); ++po; } } }
public PaillierCryptoSystem(int a, int b) { p = a; q = b; n = BigInteger.valueOf(p).multiply(BigInteger.valueOf(q)); lambda = psi = lcm(p - 1, q - 1); g = n.add(BigInteger.valueOf(1)); nu = psi.modInverse(n); }
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 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); }
private void constrain() { BigInteger offset = new BigInteger(Integer.toString(addressSize * (numUsableRows))); BigInteger endVal = startVal.add(offset); if (endVal.compareTo(scrollBar.getMaximumHP()) > 0) { startVal = scrollBar.getMaximumHP().subtract(offset); endVal = scrollBar.getMaximumHP(); scrollBar.setValueHP(startVal); model.fireTableDataChanged(); } }
public PaillierCryptoSystem() { p = 100000 + (new Random().nextInt(4) + 1) * 10000 + 1; while (!isPrime(p)) p += 2; q = p + 2; while (!isPrime(q)) q += 2; n = BigInteger.valueOf(p).multiply(BigInteger.valueOf(q)); lambda = psi = lcm(p - 1, q - 1); g = n.add(BigInteger.valueOf(1)); nu = psi.modInverse(n); }
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); }
void work() { cin = new Scanner(System.in); int n = cin.nextInt(); BigInteger a = BigInteger.ONE; BigInteger b = BigInteger.ONE; n -= 1; for (int i = 0; i < n; i++) { BigInteger c = a.add(b); a = b; b = c; } System.out.println(b.toString()); }
public static void main(String[] args) { Scanner cin = new Scanner(System.in); int Case = 0; int t = cin.nextInt(); while (t > 0) { t--; if (Case != 0) System.out.println(); ; BigInteger a = cin.nextBigInteger(); BigInteger b = cin.nextBigInteger(); System.out.println("Case " + (++Case) + ":"); System.out.println(a + " + " + b + " = " + a.add(b)); } }
public static void main(String args[]) { Scanner in = new Scanner(System.in); int T; BigInteger sum = new BigInteger("0"); BigInteger aux = new BigInteger("0"); T = in.nextInt(); for (int i = 0; i < T; i++) { aux = in.nextBigInteger(); sum = sum.add(aux); } System.out.println(sum); }
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 main(String[] args) { BigInteger pCorr = new BigInteger("2"); BigInteger pInc = new BigInteger("1"); BigInteger incorrects = new BigInteger("0"); // loop calculates number of hads in each incorrect iteration for (int x = 0; x < 100; x++) { // 6 + 2*pInc + pCorr pInc = pInc.pCorr = place; System.out.println(place + ""); incorrects.add(new BigInteger(place + "")); } System.out.println(incorrects); }
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); }
/** Test probable primes in the sieve and return successful candidates. */ BigInteger retrieve(BigInteger initValue, int certainty, java.util.Random random) { // Examine the sieve one long at a time to find possible primes int offset = 1; for (int i = 0; i < bits.length; i++) { long nextLong = ~bits[i]; for (int j = 0; j < 64; j++) { if ((nextLong & 1) == 1) { BigInteger candidate = initValue.add(BigInteger.valueOf(offset)); if (candidate.primeToCertainty(certainty, random)) return candidate; } nextLong >>>= 1; offset += 2; } } return null; }
public static void main(String args[]) { int n, c; BigInteger inc = new BigInteger("1"); BigInteger fact = new BigInteger("1"); Scanner input = new Scanner(System.in); n = input.nextInt(); for (c = 1; c <= n; c++) { fact = fact.multiply(inc); inc = inc.add(BigInteger.ONE); } System.out.println(n + "! = " + fact); }
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++; } }
/** @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); }
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); }
public fraction negate() { return new fraction(num.negate(), den.add(BigInteger.ZERO)); }
public BigInteger combine(BigInteger x, BigInteger y) { return x.add(y); }