本文整理汇总了Java中java.math.BigInteger.divide方法的典型用法代码示例。如果您正苦于以下问题:Java BigInteger.divide方法的具体用法?Java BigInteger.divide怎么用?Java BigInteger.divide使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.math.BigInteger
的用法示例。
在下文中一共展示了BigInteger.divide方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: pollardRho
import java.math.BigInteger; //导入方法依赖的package包/类
/**
* Pollard's Rho cracking algorithm
* @param pbKey Public key to crack
* @param pbExp Public exponent of the key to crack
*/
public static void pollardRho(BigInteger pbKey, BigInteger pbExp) {
BigInteger p;
BigInteger x = new BigInteger("2");
BigInteger y = x;
do {
x = x.multiply(x).add(BigInteger.ONE).mod(pbKey);
y = y.multiply(y).add(BigInteger.ONE).mod(pbKey);
y = y.multiply(y).add(BigInteger.ONE).mod(pbKey);
p = x.subtract(y).gcd(pbKey);
} while (p.compareTo(BigInteger.ONE) == 0);
if (p.compareTo(pbKey) == 0)
return;
BigInteger q = pbKey.divide(p);
calcPrivateExp(p, q, pbExp);
}
示例2: init
import java.math.BigInteger; //导入方法依赖的package包/类
/**
* This method is the core of all constructors. It takes the numerator and
* the denominator as BigIntegers and produces a BigRational, reducing the
* fraction if needed.
*
* @param numerator The numerator of the rational number
* @param denominator The denominator of the rational number
* @param isNormal True if the fraction is already in reduced form, false otherwise.
*/
private void init(BigInteger numerator, BigInteger denominator, boolean isNormal) {
// If isNormal, then we do not need to reduce the fraction and compute the gcd
// deal with x / 0
if (denominator.equals(BigInteger.ZERO)) {
throw new RuntimeException("Denominator is zero");
}
if (!isNormal) {
// reduce fraction
BigInteger g = numerator.gcd(denominator);
num = numerator.divide(g);
den = denominator.divide(g);
} else {
num = numerator;
den = denominator;
}
}
示例3: toBase56
import java.math.BigInteger; //导入方法依赖的package包/类
private static String toBase56(byte[] value) {
StringBuilder builder = new StringBuilder();
BigInteger quotient = new BigInteger(value);
BigInteger base = new BigInteger("56");
int size = 0;
while (quotient.compareTo(BigInteger.ZERO) > 0 || size < PASSWORD_SIZE) {
int remainder = quotient.mod(base).intValue();
builder.append(BASE56_ENCODING_CHARS.charAt(remainder));
quotient = quotient.divide(base);
size++;
}
return builder.toString();
}
示例4: bigIntegerReverse
import java.math.BigInteger; //导入方法依赖的package包/类
/**
* Reverses the digits of a {@link BigInteger}.
* (123456789 --> 987654321)
*
* @param n The BigInteger.
* @param abort An {@link AtomicBoolean} used to abort the execution
* for whatever reason; Can be null.
* @throws NullPointerException if {@code n} is null.
* @throws IllegalArgumentException if {@code n} is less than or equal to zero.
* @return The reverse of {@code n}, {@code null} if aborted.
*/
static BigInteger bigIntegerReverse(final BigInteger n, final AtomicBoolean abort) {
if (n == null)
throw new NullPointerException("n value can't be null");
if (n.compareTo(ZERO) <= 0)
throw new IllegalArgumentException("n value must be greater than zero");
BigInteger test = n;
BigInteger reverse = ZERO;
while (test.compareTo(ZERO) != 0) {
reverse = reverse.multiply(TEN).add(test.divideAndRemainder(TEN)[1]);
test = test.divide(TEN);
if (abort != null && abort.get())
return null;
}
return reverse;
}
示例5: bigIntSqRootFloor
import java.math.BigInteger; //导入方法依赖的package包/类
public static BigInteger bigIntSqRootFloor(BigInteger x)
throws IllegalArgumentException {
if (x.compareTo(BigInteger.ZERO) < 0) {
throw new IllegalArgumentException("Negative argument.");
}
// square roots of 0 and 1 are trivial and
// y == 0 will cause a divide-by-zero exception
if (x .equals(BigInteger.ZERO) || x.equals(BigInteger.ONE)) {
return x;
} // end if
BigInteger two = BigInteger.valueOf(2L);
BigInteger y;
// starting with y = x / 2 avoids magnitude issues with x squared
for (y = x.divide(two);
y.compareTo(x.divide(y)) > 0;
y = ((x.divide(y)).add(y)).divide(two));
return y;
}
示例6: bigIntSqRootCeil
import java.math.BigInteger; //导入方法依赖的package包/类
public static BigInteger bigIntSqRootCeil(BigInteger x) throws IllegalArgumentException {
if (x.compareTo(BigInteger.ZERO) < 0) {
throw new IllegalArgumentException("Negative argument.");
}
// square roots of 0 and 1 are trivial and
// y == 0 will cause a divide-by-zero exception
if (x == BigInteger.ZERO || x == BigInteger.ONE) {
return x;
} // end if
BigInteger two = BigInteger.valueOf(2L);
BigInteger y;
// starting with y = x / 2 avoids magnitude issues with x squared
for (y = x.divide(two);
y.compareTo(x.divide(y)) > 0;
y = ((x.divide(y)).add(y)).divide(two));
if (x.compareTo(y.multiply(y)) == 0) {
return y;
} else {
return y.add(BigInteger.ONE);
}
}
示例7: split
import java.math.BigInteger; //导入方法依赖的package包/类
public byte[][] split(int n) {
Preconditions.checkArgument(lastRowInt.compareTo(firstRowInt) > 0,
"last row (%s) is configured less than first row (%s)", lastRow,
firstRow);
// +1 to range because the last row is inclusive
BigInteger range = lastRowInt.subtract(firstRowInt).add(BigInteger.ONE);
Preconditions.checkState(range.compareTo(BigInteger.valueOf(n)) >= 0,
"split granularity (%s) is greater than the range (%s)", n, range);
BigInteger[] splits = new BigInteger[n - 1];
BigInteger sizeOfEachSplit = range.divide(BigInteger.valueOf(n));
for (int i = 1; i < n; i++) {
// NOTE: this means the last region gets all the slop.
// This is not a big deal if we're assuming n << MAXHEX
splits[i - 1] = firstRowInt.add(sizeOfEachSplit.multiply(BigInteger
.valueOf(i)));
}
return convertToBytes(splits);
}
示例8: calcDifficulty
import java.math.BigInteger; //导入方法依赖的package包/类
@Override
public BigInteger calcDifficulty(BlockHeader curBlock, BlockHeader parent) {
BigInteger pd = parent.getDifficultyBI();
BigInteger quotient = pd.divide(getConstants().getDIFFICULTY_BOUND_DIVISOR());
BigInteger sign = getCalcDifficultyMultiplier(curBlock, parent);
BigInteger fromParent = pd.add(quotient.multiply(sign));
BigInteger difficulty = max(getConstants().getMINIMUM_DIFFICULTY(), fromParent);
int explosion = getExplosion(curBlock, parent);
if (explosion >= 0) {
difficulty = max(getConstants().getMINIMUM_DIFFICULTY(), difficulty.add(BigInteger.ONE.shiftLeft(explosion)));
}
return difficulty;
}
示例9: visitArithmeticBinary
import java.math.BigInteger; //导入方法依赖的package包/类
@Override
public BigInteger visitArithmeticBinary(ArithmeticBinaryContext ctx)
{
BigInteger left = visit(ctx.left);
BigInteger right = visit(ctx.right);
switch (ctx.operator.getType()) {
case PLUS:
return left.add(right);
case MINUS:
return left.subtract(right);
case ASTERISK:
return left.multiply(right);
case SLASH:
return left.divide(right);
default:
throw new IllegalStateException("Unsupported binary operator " + ctx.operator.getText());
}
}
示例10: ModularSolverParallelTask
import java.math.BigInteger; //导入方法依赖的package包/类
/**
* Creates a ModularSolverParallelTask for solving a residual linear system.
* @param mod The prime modulo corresponding to this system
* @param M The product of all prime moduli
*/
public ModularSolverParallelTask(BigInteger mod, BigInteger M) {
this.mod = mod;
this.M = M;
BigInteger Mi = M.divide(mod);
factor = Mi.modInverse(mod).multiply(Mi); //<Mi(-1)>Ni (modular multiplicative inverse)
}
示例11: getTotalSent
import java.math.BigInteger; //导入方法依赖的package包/类
/**
* Returns the amount of bitcoin ever sent via output. If an output is sent to our own wallet, because of change or
* rotating keys or whatever, we do not count it. If the wallet was
* involved in a shared transaction, i.e. there is some input to the transaction that we don't have the key for, then
* we multiply the sum of the output values by the proportion of satoshi coming in to our inputs. Essentially we treat
* inputs as pooling into the transaction, becoming fungible and being equally distributed to all outputs.
* @return the total amount of satoshis sent by us
*/
public Coin getTotalSent() {
Coin total = Coin.ZERO;
for (Transaction tx: transactions.values()) {
// Count spent outputs to only if they were not to us. This means we don't count change outputs.
Coin txOutputTotal = Coin.ZERO;
for (TransactionOutput out : tx.getOutputs()) {
if (out.isMine(this) == false) {
txOutputTotal = txOutputTotal.add(out.getValue());
}
}
// Count the input values to us
Coin txOwnedInputsTotal = Coin.ZERO;
for (TransactionInput in : tx.getInputs()) {
TransactionOutput prevOut = in.getConnectedOutput();
if (prevOut != null && prevOut.isMine(this)) {
txOwnedInputsTotal = txOwnedInputsTotal.add(prevOut.getValue());
}
}
// If there is an input that isn't from us, i.e. this is a shared transaction
Coin txInputsTotal = tx.getInputSum();
if (txOwnedInputsTotal != txInputsTotal) {
// multiply our output total by the appropriate proportion to account for the inputs that we don't own
BigInteger txOutputTotalNum = new BigInteger(txOutputTotal.toString());
txOutputTotalNum = txOutputTotalNum.multiply(new BigInteger(txOwnedInputsTotal.toString()));
txOutputTotalNum = txOutputTotalNum.divide(new BigInteger(txInputsTotal.toString()));
txOutputTotal = Coin.valueOf(txOutputTotalNum.longValue());
}
total = total.add(txOutputTotal);
}
return total;
}
示例12: revert
import java.math.BigInteger; //导入方法依赖的package包/类
@Override
public BigInteger revert(BigInteger value, BigInteger constantInt) throws TraceException {
if (constantInt.compareTo(BigInteger.valueOf(0)) == 0) {
throw new TraceException("Cannot revert MUL if the constant is 0");
}
return value.divide(constantInt);
}
示例13: divideAndRemainder
import java.math.BigInteger; //导入方法依赖的package包/类
public static void divideAndRemainder(int order) {
int failCount1 = 0;
for (int i=0; i<SIZE; i++) {
BigInteger x = fetchNumber(order).abs();
while(x.compareTo(BigInteger.valueOf(3L)) != 1)
x = fetchNumber(order).abs();
BigInteger z = x.divide(BigInteger.valueOf(2L));
BigInteger y[] = x.divideAndRemainder(x);
if (!y[0].equals(BigInteger.ONE)) {
failCount1++;
System.err.println("fail1 x :"+x);
System.err.println(" y :"+y);
}
else if (!y[1].equals(BigInteger.ZERO)) {
failCount1++;
System.err.println("fail2 x :"+x);
System.err.println(" y :"+y);
}
y = x.divideAndRemainder(z);
if (!y[0].equals(BigInteger.valueOf(2))) {
failCount1++;
System.err.println("fail3 x :"+x);
System.err.println(" y :"+y);
}
}
report("divideAndRemainder for " + order + " bits", failCount1);
}
示例14: tonellishanks
import java.math.BigInteger; //导入方法依赖的package包/类
public static BigInteger tonellishanks(BigInteger n, BigInteger p) {
//1. By factoring out powers of 2, find Q and S such that p-1=Q2^S p-1=Q*2^S and Q is odd
BigInteger p_1 = p.subtract(BigInteger.ONE);
BigInteger S = BigInteger.ZERO;
BigInteger Q = p_1;
BigInteger two = BigInteger.valueOf(2);
System.out.println("p : " + Util.bytesToHex(p.toByteArray()));
System.out.println("p is prime: " + p.isProbablePrime(10));
System.out.println("n : " + Util.bytesToHex(n.toByteArray()));
System.out.println("Q : " + Util.bytesToHex(Q.toByteArray()));
System.out.println("S : " + Util.bytesToHex(S.toByteArray()));
while (Q.mod(two).compareTo(BigInteger.ONE) != 0) { //while Q is not odd
Q = p_1.divide(two.modPow(S, p));
S = S.add(BigInteger.ONE);
//System.out.println("Iter n: " + bytesToHex(n.toByteArray()));
//System.out.println("Iter Q: " + bytesToHex(Q.toByteArray()));
//System.out.println("Iter S: " + bytesToHex(S.toByteArray()));
}
//System.out.println("n: " + bytesToHex(n.toByteArray()));
//System.out.println("Q: " + bytesToHex(Q.toByteArray()));
//System.out.println("S: " + bytesToHex(S.toByteArray()));
return n;
}
示例15: getValueShortString
import java.math.BigInteger; //导入方法依赖的package包/类
public static String getValueShortString(BigInteger number) {
BigInteger result = number;
int pow = 0;
while (result.compareTo(_1000_) == 1 || result.compareTo(_1000_) == 0) {
result = result.divide(_1000_);
pow += 3;
}
return result.toString() + "\u00b7(" + "10^" + pow + ")";
}