a ^ b mod c 我知道如果c是素数如何解决,如果c不是素数,那将是什么方法。 任何数学方法。
答案 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.