List of usage examples for java.math BigInteger multiply
BigInteger multiply(long v)
From source file:Main.java
public static BigInteger pow(BigInteger base, BigInteger exponent) { BigInteger result = BigInteger.ONE; while (exponent.signum() > 0) { if (exponent.testBit(0)) result = result.multiply(base); base = base.multiply(base);//from w ww . j av a 2 s . c o m exponent = exponent.shiftRight(1); } return result; }
From source file:Main.java
public static BigInteger hashFnv1A(byte[] data) { final BigInteger INIT64 = new BigInteger("cbf29ce484222325", 16); final BigInteger PRIME64 = new BigInteger("100000001b3", 16); final BigInteger MOD64 = new BigInteger("2").pow(64); BigInteger hash = INIT64; for (byte b : data) { hash = hash.xor(BigInteger.valueOf((int) b & 0xff)); hash = hash.multiply(PRIME64).mod(MOD64); }/*from w w w .j av a 2 s . c o m*/ return hash; }
From source file:edu.hku.sdb.udf.util.UDFHandler.java
/** * Calculates the ciphertext ce according to updated p, q values during A's keyUpdate operation. * * @param a the ciphertext of A, whose value < n * @param s the ciphertext of helper S, whose value < n * @param p the new p generated in A's keyUpdate operation * @param q the new q generated in A's keyUpdate operation * @param n// w w w . ja v a2 s. c o m * @return */ public static BigInteger keyUpdate(BigInteger a, BigInteger s, BigInteger p, BigInteger q, BigInteger n) { BigInteger sp = s.modPow(p, n); return (q.multiply(a).multiply(sp)).mod(n); }
From source file:edu.hku.sdb.udf.util.UDFHandler.java
/** * Returns (ae * be) mod n according to SDB Multiplication (EE Mode) protocol * * @param multiplicand ae, whose value < n * @param multiplier be, whose value < n * @param n/* w ww. j a v a 2s . c o m*/ * @return */ public static BigInteger multi(BigInteger multiplicand, BigInteger multiplier, BigInteger n) { BigInteger result = (multiplicand.multiply(multiplier)).mod(n); return result; }
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 w w w .j a v a2s. c o m } 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:org.apache.hadoop.hbase.manual.utils.HBaseUtils.java
/** * Splits the given BigInteger into numberOfSplits parts * @param maxValue//from w ww .java 2 s . c o m * @param numberOfSplits * @return array of BigInteger which is of size (numberOfSplits-1) */ private static BigInteger[] split(BigInteger maxValue, int numberOfSplits) { BigInteger[] splits = new BigInteger[numberOfSplits - 1]; BigInteger sizeOfEachSplit = maxValue.divide(BigInteger.valueOf(numberOfSplits)); for (int i = 1; i < numberOfSplits; i++) { splits[i - 1] = sizeOfEachSplit.multiply(BigInteger.valueOf(i)); } return splits; }
From source file:cc.redberry.core.number.Exponentiation.java
public static Complex findIntegerRoot(Complex base, BigInteger power) { BigInteger rDenominator = ((Rational) base.getReal()).getDenominator(); BigInteger iDenominator = ((Rational) base.getImaginary()).getDenominator(); BigInteger lcm = rDenominator.gcd(iDenominator); lcm = rDenominator.divide(lcm);//from www. j av a 2s . co m lcm = lcm.multiply(iDenominator); BigInteger lcmRoot = findIntegerRoot(lcm, power); if (lcm == null) return null; base = base.multiply(lcm); Complex numericValue = base.pow(1.0 / power.doubleValue()); double real = numericValue.getReal().doubleValue(); double imaginary = numericValue.getImaginary().doubleValue(); int ceilReal = (int) Math.ceil(real), floorReal = (int) Math.floor(real), ceilImaginary = (int) Math.ceil(imaginary), floorImaginary = (int) Math.floor(imaginary); Complex candidate; if ((candidate = new Complex(ceilReal, ceilImaginary)).pow(power).equals(base)) return candidate.divide(lcmRoot); if ((candidate = new Complex(floorReal, ceilImaginary)).pow(power).equals(base)) return candidate.divide(lcmRoot); if ((candidate = new Complex(ceilReal, floorImaginary)).pow(power).equals(base)) return candidate.divide(lcmRoot); if ((candidate = new Complex(floorReal, floorImaginary)).pow(power).equals(base)) return candidate.divide(lcmRoot); return null; }
From source file:edu.utah.further.core.api.math.ArithmeticUtil.java
/** * Compute the factorial of a {@link BigInteger}. Allows computing big numbers. * * @param n/*from w w w. j a va 2s. com*/ * @return */ public static BigInteger factorial(final int n) { BigInteger fact = BigInteger.ONE; for (int i = n; i > 1; i--) { fact = fact.multiply(new BigInteger(Integer.toString(i))); } return fact; }
From source file:gedi.util.math.stat.distributions.OccupancyNumberDistribution.java
private static final BigInteger factorial(int b) { if (b == 0)/*from ww w. j a v a 2 s. co m*/ return BigInteger.ONE; BigInteger re = BigInteger.valueOf(b); for (int i = b - 1; i > 1; i--) re = re.multiply(BigInteger.valueOf(i)); return re; }
From source file:gedi.util.math.stat.distributions.OccupancyNumberDistribution.java
private static final BigInteger factorial(int b, int k) { if (b == 0 || k == 0) return BigInteger.ONE; BigInteger re = BigInteger.valueOf(b); for (int i = b - 1; i > b - k; i--) re = re.multiply(BigInteger.valueOf(i)); return re;/* w ww . ja va 2 s . co m*/ }