List of usage examples for java.math BigInteger multiply
BigInteger multiply(long v)
From source file:Main.java
public static void main(String[] argv) throws Exception { BigInteger bi1 = new BigInteger("1234567890123456890"); BigInteger bi2 = BigInteger.valueOf(123L); bi1 = bi1.multiply(bi2); }
From source file:Main.java
public static void main(String[] argv) throws Exception { BigInteger bi1 = new BigInteger("1234567890123456890"); BigInteger bi2 = BigInteger.valueOf(123L); bi1 = bi1.multiply(bi2); bi1 = bi1.subtract(bi2);// ww w . j av a 2 s.c om bi1 = bi1.divide(bi2); bi1 = bi1.negate(); }
From source file:BigIntegerTest.java
public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("How many numbers do you need to draw? "); int k = in.nextInt(); System.out.print("What is the highest number you can draw? "); int n = in.nextInt(); /*/*from ww w .jav a 2s . com*/ * compute binomial coefficient n*(n-1)*(n-2)*...*(n-k+1)/(1*2*3*...*k) */ BigInteger lotteryOdds = BigInteger.valueOf(1); for (int i = 1; i <= k; i++) lotteryOdds = lotteryOdds.multiply(BigInteger.valueOf(n - i + 1)).divide(BigInteger.valueOf(i)); System.out.println("Your odds are 1 in " + lotteryOdds + ". Good luck!"); }
From source file:Main.java
public static void main(String[] args) { BigInteger bi1 = new BigInteger("7"); BigInteger bi2 = new BigInteger("20"); // multiply bi1 with bi2 and assign result to bi3 BigInteger bi3 = bi1.multiply(bi2); System.out.println(bi3);/*from w ww . j av a2s. co 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);//from ww w.ja va 2s. c o 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);// w ww. j a va 2 s. co 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:edu.macalester.tagrelatedness.KendallsCorrelation.java
public static void main(String args[]) { long tiedx = new BigInteger("1853724906736").longValue(); long tiedy = new BigInteger("5328254589").longValue(); long numpairs = new BigInteger("4094164093575").longValue(); BigSquareRoot sqrt = new BigSquareRoot(); BigInteger first = new BigInteger("" + (numpairs - tiedx)); BigInteger second = new BigInteger("" + (numpairs - tiedy)); BigDecimal result = sqrt.get(first.multiply(second)); System.out.println(result.doubleValue()); }
From source file:Main.java
/** * Symmetric encryption of private key x * @param u/* w ww . j a v a 2s. c o m*/ * @param k * @param p * @param x * @return */ public static BigInteger getE(BigInteger u, BigInteger k, BigInteger p, BigInteger x) { return u.multiply(x).subtract(k).mod(p.subtract(BigInteger.ONE)); }
From source file:Main.java
public static BigInteger productOf(Collection<Integer> numbers) { BigInteger sum = BigInteger.ONE; for (Integer n : numbers) { sum = sum.multiply(BigInteger.valueOf(n)); }//w ww . java 2 s . co m return sum; }
From source file:FactQuoter.java
/** The factorial() method, using BigIntegers cached in a ArrayList */ public static synchronized BigInteger factorial(int x) { if (x < 0) throw new IllegalArgumentException("x must be non-negative."); for (int size = table.size(); size <= x; size++) { BigInteger lastfact = (BigInteger) table.get(size - 1); BigInteger nextfact = lastfact.multiply(BigInteger.valueOf(size)); table.add(nextfact);//from w w w . j a v a 2s . co m } return (BigInteger) table.get(x); }