Number theory related algorithms (algorithm only)

1.BSGS

purposes: Solving the form $ A ^ x \ equiv z (is a prime number).

Solution:

Consider violence, violence 0 to p-1 enumeration and verification, complexity of O (n).

Optimization considerations: Consider accelerated by preprocessing algorithm.

$$ A ^ x \ equiv z (

provided $ c $ = $ \ sqrt {which is our block size,

$$ IC + A ^ {J} \ equiv Z (P MOD) $$

$$ a ^ J \ equiv Z * a ^ {-} IC (P MOD) $$

we $ 1 to $ c $ $ $ a ^ i $ a hash into the pool, so that every time we enumerate $ A ^ {- ic} * zso we can verify whether the value of $ c $ simultaneously occur.

Complexity of O ($ \ sqrt {n}

Development BSGS:

$$ A ^ X \ equiv Z (P MOD) $$

while taking sides t = gcd (A, P)

Original formula:

$$. 1-A ^ {X} * \ FRAC {A} {} T * T \ equiv \ FRAC Z {} {} T * T (MOD \ FRAC {P} {} T * T) $$

then, now becomes the original formula:

$$. 1-A ^ {X} * \ FRAC {A} {} T \ equiv \ FRAC {Z} {T} (MOD * \ FRAC {P} {T}) $$

this process takes place until the A, P coprime.

Obviously, when z is not divisible in the middle, it is no solution.

Now, the original formula becomes:

$$ XK} * {A ^ C \ equiv T (P MOD) $$

Because $ C $ is composed of several inter A number of other factors obtained, and $ C $ $ $ P must also prime.

By Euler's theorem to $ C $ of the inverse of multiplication to the right, you can then use ordinary BSGS.

Note that the last time counted answer $ A $ is a reduction of $ K $ and $ K $ we put together on the line.

Guess you like

Origin www.cnblogs.com/wuzewen/p/11121249.html