如何计算(a ^ b)mod c其中b很大而c不是素数?

时间:2016-10-15 10:52:27

标签: math

a ^ b mod c 我知道如果c是素数如何解决,如果c不是素数,那将是什么方法。 任何数学方法。

1 个答案:

答案 0 :(得分:0)

Assuming the factorization of c is known, you can compute the Euler totient value phi(c) and know that with that number, but only if a and c have no common divisors,

a^b == a^( b mod phi(c) )  mod c

Thus if b is, as in your original edit, some very very large Fibonacci number, you have to compute this number with the algorithm of your choice with all arithmetic operations mod phi(c). This at the same time ensures that the exponent stays inside the same number format as used for c and that the complexity of the exponentiation is reduced.