I use JavaScript with my own BigInteger library, I have a problem with the complexity of the mod function.
// r = big1 - (big2 * (big1/big2))
function mod(big1, big2){
return subs(big1, multiply(big2, divide(big1,big2)));
}
//r = b1 % b2
a different approach is to operate modulus by parts (say your limit for a number is 9 digits per number and say b2 < 100):
final outcome is b1%b2. If also b2 is very large this will not work, but if only b1 is very large you can treat it is a string for the purpose of the algorithm.
coding it should be easy with iteration since you can know the number of iterations beforehand, don't even need recursion.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.