编写java程序,计算2个大整数的和.差.积和商,计算出一个大整数的因子个数(因子个数不包括1和大整数本身

来源:百度知道 编辑:UC知道 时间:2024/06/27 13:12:33

class BigInt {
private final BigInteger value;

public BigInt(String integer) {
value = new BigInteger(integer);
}

private BigInt(BigInteger integer) {
value = integer;
}

public BigInt add(BigInt integer) {
return new BigInt(value.add(integer.value));
}

public BigInt subtract(BigInt integer) {
return new BigInt(value.subtract(integer.value));
}

public BigInt multiply(BigInt integer) {
return new BigInt(value.multiply(integer.value));
}

public BigInt divide(BigInt integer) {
return new BigInt(value.divide(integer.value));
}

public int factorCount() {
int count = 0;
for (BigInteger i = BigInteger.valueOf(2); i.compareTo(value) < 0;
i = i.add(BigInteger.ONE)) {
if (value.remainder(i).equals(BigInteger.ZERO)) {
++count;
}
}
return count;
}