List of usage examples for java.math BigInteger ZERO
BigInteger ZERO
To view the source code for java.math BigInteger ZERO.
Click Source Link
From source file:Main.java
public static void main(String[] args) { BigInteger numberB = BigInteger.ZERO; }
From source file:PalindromeBig.java
public static void main(String[] argv) { for (int i = 0; i < argv.length; i++) try {//from w w w . j a v a 2 s . c o m BigInteger l = new BigInteger(argv[i]); if (l.compareTo(BigInteger.ZERO) < 0) { System.err.println(argv[i] + " -> TOO SMALL"); continue; } System.out.println(argv[i] + "->" + findPalindrome(l)); } catch (NumberFormatException e) { System.err.println(argv[i] + "-> INVALID"); } catch (IllegalStateException e) { System.err.println(argv[i] + "-> " + e); } }
From source file:Main.java
public static BigInteger sumOf(Collection<Integer> numbers) { BigInteger sum = BigInteger.ZERO; for (Integer n : numbers) { sum = sum.add(BigInteger.valueOf(n)); }/* w w w . j a va2 s. c om*/ return sum; }
From source file:Main.java
public static BigInteger getZ(ArrayList<byte[]> c1, ArrayList<byte[]> c2, BigInteger p) { BigInteger z = BigInteger.ZERO; //TODO: make sure c1 and c2 are of the same size int size = c1.size(); if (size > c2.size()) { size = c2.size();/*from ww w . ja v a 2 s .c om*/ } for (int i = 0; i < size; i++) { BigInteger c1BI = new BigInteger(1, c1.get(i)); BigInteger c2BI = new BigInteger(1, c2.get(i)); BigInteger exp = new BigInteger(1, ByteBuffer.allocate(8).putLong((long) Math.pow(2, i)).array()); z = z.add((c1BI.multiply(c2BI)).modPow(exp, p)); Log.d("CeCk", "z calculation " + i + "/" + size + " round"); } return z.mod(p); }
From source file:Main.java
static BigInteger mulmod(BigInteger a, BigInteger b, BigInteger p) { BigInteger r = BigInteger.ZERO; while (b.compareTo(BigInteger.ZERO) > 0) { if (!b.and(BigInteger.ONE).equals(BigInteger.ZERO)) { r = addmod(r, a, p);/* w w w . j a va2s . c om*/ } b = b.shiftRight(1); a = addmod(a, a, p); } return r; }
From source file:Main.java
static BigInteger inverseMod(BigInteger a, BigInteger b) { BigInteger b0 = b, t, q;//from w w w.j a va 2 s . com BigInteger x0 = BigInteger.ZERO, x1 = BigInteger.ONE; if (b.equals(BigInteger.ONE)) return BigInteger.ONE; while (a.subtract(BigInteger.ONE).signum() > 0) { q = a.divide(b); t = b; b = a.mod(b); a = t; t = x0; x0 = x1.subtract(q.multiply(x0)); x1 = t; } if (x1.signum() < 0) x1 = x1.add(b0); return x1; }
From source file:Main.java
/** find a palindromic number given a starting point, by * calling ourself until we get a number that is palindromic. *///from w w w. j a v a 2 s .c om public static BigInteger findPalindrome(BigInteger num) { if (num.compareTo(BigInteger.ZERO) < 0) throw new IllegalStateException("negative"); if (isPalindrome(num)) return num; if (verbose) System.out.println("Trying " + num); return findPalindrome(num.add(reverseNumber(num))); }
From source file:Main.java
public static String toBase58(byte[] b) { if (b.length == 0) { return ""; }/* www . j a va2 s. c om*/ int lz = 0; while (lz < b.length && b[lz] == 0) { ++lz; } StringBuffer s = new StringBuffer(); BigInteger n = new BigInteger(1, b); while (n.compareTo(BigInteger.ZERO) > 0) { BigInteger[] r = n.divideAndRemainder(BigInteger.valueOf(58)); n = r[0]; char digit = b58[r[1].intValue()]; s.append(digit); } while (lz > 0) { --lz; s.append("1"); } return s.reverse().toString(); }
From source file:ec.edu.distri.clientejava.protocolo.model.Canal.java
public Canal() { costo = new BigDecimal(BigInteger.ZERO); }
From source file:Main.java
/** * Convert to base 128 (bigendian), using shifts. * @param val/* ww w. j a v a 2 s . c om*/ * @return */ public static ArrayList<Integer> base128(BigInteger val) { ArrayList<Integer> result = new ArrayList<Integer>(); int part = val.and(BN127).intValue(); val = val.shiftRight(7); result.add(0, new Integer(part)); while (!val.equals(BigInteger.ZERO)) { part = val.and(BN127).intValue(); val = val.shiftRight(7); part += 128; result.add(0, new Integer(part)); } ; return result; }