I need to find an efficient algorithm for doing modular multiplication of three numbers.
In other words is there a way to find this in C?
(100100101010001001 * 1010000100100010 * 10010001001010100101001) % 1000000007
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you are looking to avoid integer overflow, you can transform
into
In C:
It can still overflow though, but less often than the naïve version. If you want to be positively sure it will not overflow then you should use some form of big numbers library like gmplib. The usage would look like:
Maybe Gmplib supports directly setting the result into the same variable as one of the operand but I am not sure. You would have to check this in the documentation.