List of usage examples for java.math BigInteger pow
public BigInteger pow(int exponent)
(thisexponent)
. From source file:Main.java
public static void main(String[] argv) throws Exception { BigInteger bi1 = new BigInteger("1234567890123456890"); int exponent = 2; bi1 = bi1.pow(exponent); }
From source file:Main.java
public static void main(String[] args) { int exponent = 2; // assign value to bi1 BigInteger bi1 = new BigInteger("6"); // perform pow operation on bi1 using exponent BigInteger bi2 = bi1.pow(exponent); System.out.println(bi2);/*from w w w .j a va 2s .c o m*/ }
From source file:Main.java
public static void main(String[] argv) throws Exception { // Create via a string BigInteger bi1 = new BigInteger("1234567890123456890"); // Create via a long BigInteger bi2 = BigInteger.valueOf(123L); bi1 = bi1.add(bi2);/* w w w . ja v a2 s . co m*/ bi1 = bi1.multiply(bi2); bi1 = bi1.subtract(bi2); bi1 = bi1.divide(bi2); bi1 = bi1.negate(); int exponent = 2; bi1 = bi1.pow(exponent); }
From source file:Main.java
public static void main(String[] args) { BigInteger numberA = new BigInteger("98765432123456789"); BigInteger numberB = BigInteger.TEN; numberA = numberA.add(numberB);//from w w w.j av a 2s .c o m System.out.println("numberA = " + numberA); numberA = numberA.multiply(numberB); System.out.println("numberA = " + numberA); numberA = numberA.subtract(numberB); System.out.println("numberA = " + numberA); numberA = numberA.divide(numberB); System.out.println("numberA = " + numberA); numberA = numberA.mod(numberB); System.out.println("numberA = " + numberA); numberA = numberA.pow(2); System.out.println("numberA = " + numberA); numberA = numberA.negate(); System.out.println("numberA = " + numberA); }
From source file:Main.java
private static BigInteger findSquareRoot(BigInteger alpha, BigInteger p) { BigInteger beta = null;//www . j av a 2s. c o m if (p.mod(BigInteger.valueOf(4)).compareTo(BigInteger.valueOf(3)) == 0) { BigInteger k = p.shiftRight(2).add(ONE); beta = alpha.modPow(k, p); } else if (p.mod(BigInteger.valueOf(8)).compareTo(BigInteger.valueOf(5)) == 0) { System.out.println("p = 8 mod 5"); BigInteger k = p.subtract(BigInteger.valueOf(5)).divide(BigInteger.valueOf(8)); BigInteger gamma = alpha.multiply(BigInteger.valueOf(2)).modPow(k, p); BigInteger i = alpha.multiply(BigInteger.valueOf(2)).multiply(gamma.pow(2)).mod(p); beta = alpha.multiply(gamma).multiply(i.subtract(ONE)).mod(p); } else if (p.mod(BigInteger.valueOf(8)).compareTo(BigInteger.valueOf(1)) == 0) { beta = null; //TODO System.out.println("finding square root not fully implemented yet"); } return beta; }
From source file:cc.redberry.core.number.NumberUtils.java
public static boolean isSqrt(BigInteger n, BigInteger root) { return n.compareTo(root.pow(2)) == 0; }
From source file:cc.redberry.core.number.NumberUtils.java
private static boolean isSqrtXXX(BigInteger n, BigInteger root) { final BigInteger lowerBound = root.pow(2); final BigInteger upperBound = root.add(BigInteger.ONE).pow(2); return lowerBound.compareTo(n) <= 0 && n.compareTo(upperBound) < 0; }
From source file:Main.java
public static byte[] base58ToBytes(String value) { BigInteger bigNum58 = new BigInteger("58"); BigInteger tempBigValue = new BigInteger("0"); int leadingZeroes = 0; boolean justStarted = true; for (int i = 0; i < value.length(); i++) { if (justStarted && value.toCharArray()[i] == '1') { leadingZeroes++;//from w ww. j a v a2 s . co m } else { justStarted = false; tempBigValue = tempBigValue.add(bigNum58.pow(value.length() - i - 1) .multiply(new BigInteger("" + base58Array.indexOf(value.toCharArray()[i])))); } } byte[] bigValue = tempBigValue.toByteArray(); int bigValueStart = 0; for (int j = 0; j < bigValue.length; j++) { if (bigValue[j] != 0) { bigValueStart = j; break; } } byte[] byteResult = new byte[bigValue.length + leadingZeroes - bigValueStart]; for (int i = 0; i < byteResult.length; i++) { if (i - leadingZeroes + bigValueStart < bigValue.length && i - leadingZeroes + bigValueStart >= 0) byteResult[i] = i < leadingZeroes ? 0 : bigValue[i - leadingZeroes + bigValueStart]; } return byteResult; }
From source file:com.abiquo.api.services.appslibrary.event.TemplateFactory.java
/** * Gets the disk capacity on bytes.//from w w w.jav a 2 s .c o m * * @param capacity, numeric value * @param alloctionUnit, bytes by default but can be Kb, Mb, Gb or Tb. * @return capacity on bytes **/ private static BigInteger getBytes(final String capacity, final String allocationUnits) { BigInteger capa = new BigInteger(capacity); if (allocationUnits == null) { return capa; } if ("byte".equalsIgnoreCase(allocationUnits) || "bytes".equalsIgnoreCase(allocationUnits)) { return capa; } BigInteger factor = new BigInteger("2"); if ("byte * 2^10".equals(allocationUnits) || "KB".equalsIgnoreCase(allocationUnits) || "KILOBYTE".equalsIgnoreCase(allocationUnits) || "KILOBYTES".equalsIgnoreCase(allocationUnits)) // kb { factor = factor.pow(10); } else if ("byte * 2^20".equals(allocationUnits) || "MB".equalsIgnoreCase(allocationUnits) || "MEGABYTE".equalsIgnoreCase(allocationUnits) || "MEGABYTES".equalsIgnoreCase(allocationUnits)) // mb { factor = factor.pow(20); } else if ("byte * 2^30".equals(allocationUnits) || "GB".equalsIgnoreCase(allocationUnits) || "GIGABYTE".equalsIgnoreCase(allocationUnits) || "GIGABYTES".equalsIgnoreCase(allocationUnits)) // gb { factor = factor.pow(30); } else if ("byte * 2^40".equals(allocationUnits) || "TB".equalsIgnoreCase(allocationUnits) || "TERABYTE".equalsIgnoreCase(allocationUnits) || "TERABYTES".equalsIgnoreCase(allocationUnits)) // tb { factor = factor.pow(40); } else { final String msg = "Unknow disk capacityAllocationUnits factor [" + allocationUnits + "]"; throw new RuntimeException(msg); } return capa.multiply(factor); }
From source file:gedi.util.math.stat.distributions.OccupancyNumberDistribution.java
private void computeRational() { int maxA = b == 0 ? k : Math.min(k, n / b); aToProb = new double[maxA + 1]; BigFraction[] aToProb = new BigFraction[maxA + 1]; BigInteger bfac = factorial(b); long start = System.currentTimeMillis(); double maxDiff = 0; aToProb[maxA] = BigFraction.ONE;// w ww. j a v a 2 s .c om for (int a = maxA - 1; a >= 0; a--) { int m = Math.min(k - a + 1, aToProb.length - a); aToProb[a] = BigFraction.ZERO; for (int i = 1; i < m; i++) { BigInteger rat = binomialCoefficientLargeInteger(k - a, i).multiply(factorial(n - a * b, i * b)); if (n - a * b - i * b > 0) rat = rat.multiply(BigInteger.valueOf(k - a - i).pow(n - a * b - i * b)); if (m - i > 0) rat = rat.multiply(bfac.pow(m - i)); aToProb[a] = aToProb[a].add(new BigFraction(rat, BigInteger.ONE).multiply(aToProb[a + i])); } BigInteger rat = bfac.pow(m).multiply(BigInteger.valueOf(k - a).pow(n - a * b)); aToProb[a] = BigFraction.ONE.subtract(aToProb[a].multiply(new BigFraction(BigInteger.ONE, rat))); this.aToProb[a] = new BigFraction(binomialCoefficientLargeInteger(k, a), BigInteger.ONE) .multiply(aToProb[a].multiply(rationalv(a, b, k, n))).doubleValue(); maxDiff = max(maxDiff, abs(this.aToProb[a] - approximateProbability(a))); if (System.currentTimeMillis() - start > 500) { aToProxProb = this.aToProb = computeApproximateNormal(); return; } } // System.out.printf(Locale.US,"%d\t%d\t%d\t%d\t%.4g\t%.4f\n",b,k,n,maxDigit,maxDiff,(System.currentTimeMillis()-start)/1000.0); }