문제

Example:

(30000000^30000000) mod 40000000 = ?

I have been using Euler theory and properties of exponents but still cannot get the answer Anyone know how to calculate this by just theories and simple calculator?

My trial is to reduce the exponent of the 30000000 by the Fermat's Little Theorem but the exponent is still too large for the calculator to compute.

도움이 되었습니까?

해결책

You use the halving-and-squaring approach to power computation and reduce in every step the intermediate result modulo the given divisor.

You can also use negative remainders to get somewhat smaller intermediate results.

Note also that n=40000000=4*10^7=2^9*5^7 is a composite number, so the Euler totient function gives phi(n)=2^8*4*5^6=16*10^5=160000. Now reduce the exponent mod phi(n)-1 first.

This last method only works if you know the factorization of the divisor.

다른 팁

# b^e (mod m)
function powerMod(b, e, m)
    x := 1
    while e > 0
        if e % 2 == 1
            x := (b * x) % m
        b := (b * b) % m
        e := floor(e / 2)
    return x
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top