List of usage examples for java.math BigInteger subtract
public BigInteger subtract(BigInteger val)
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.subtract(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);// www.ja v a 2s .c om bi1 = bi1.subtract(bi2); bi1 = bi1.divide(bi2); bi1 = bi1.negate(); }
From source file:Main.java
public static void main(String[] args) { BigInteger bigInteger = new BigInteger("2000000000000");// uper limit BigInteger min = new BigInteger("1000000000");// lower limit BigInteger bigInteger1 = bigInteger.subtract(min); Random rnd = new Random(); int maxNumBitLength = bigInteger.bitLength(); BigInteger aRandomBigInt;//from w w w . ja v a 2s . c om aRandomBigInt = new BigInteger(maxNumBitLength, rnd); if (aRandomBigInt.compareTo(min) < 0) aRandomBigInt = aRandomBigInt.add(min); if (aRandomBigInt.compareTo(bigInteger) >= 0) aRandomBigInt = aRandomBigInt.mod(bigInteger1).add(min); System.out.println(aRandomBigInt); }
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 w w w .j a v a2 s . 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);//ww w . j a va 2 s . 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
static BigInteger addmod(BigInteger a, BigInteger b, BigInteger p) { if (p.subtract(b).compareTo(a) > 0) { return a.add(b); } else {// w w w.java2 s .c o m return a.add(b).subtract(p); } }
From source file:Main.java
/** * Symmetric encryption of private key x * @param u//from ww w . j av a2 s. 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 modNear(BigInteger a, BigInteger b) { BigInteger res = a.mod(b); if (res.compareTo(b.shiftRight(1)) == 1) res = res.subtract(b); return res;/* w w w .j av a 2 s .c o m*/ }
From source file:Main.java
public static boolean isGoodGaAndGb(BigInteger g_a, BigInteger p) { return !(g_a.compareTo(BigInteger.valueOf(1)) != 1 || g_a.compareTo(p.subtract(BigInteger.valueOf(1))) != -1); }
From source file:Main.java
public static void main() { BigInteger bi1 = new BigInteger("123"); BigInteger bi2 = new BigInteger("-123"); // assign difference of bi1 and bi2 to bi3 BigInteger bi3 = bi1.subtract(bi2); System.out.println(bi3);/*ww w .j ava2 s . c om*/ }