问题描述
public static BigInteger primeFactorOf(BigInteger n) {
BigInteger p = n.sqrt();
BigInteger small = new BigInteger("0");
BigInteger two = new BigInteger("2");
while(n.mod(p).compareTo(small)!=0){
p=p.subtract(two);
}
System.out.println(p);
System.out.println(n.divide(p));
return p;
}
public static void main(String[] args){
BigInteger big = new BigInteger("3223956689869297");
primeFactorOf(big);
}
得到
Exception in thread "main" java.lang.ArithmeticException: BigInteger: modulus not positive
at java.base/java.math.BigInteger.mod(BigInteger.java:2692)
at matma.primeFactorOf(matma.java:125)
at matma.main(matma.java:136)
我制作了这个函数来分解两个质数的大数(在本例中为 82192031*39224687=3223956689869297
)。
虽然该函数适用于较小的数字(当素数为 6 位时),但现在当我使用 8 位素数时,我遇到了这个错误。
我不明白它以前为什么以及如何工作,现在却没有。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)