BSGS template

# Use

Given an integer a, b, P, where a, b are coprime, obtaining a positive integer x, such that A X ≡ B (P MOD)
# Derivation
The remaining cases are generated based mold cycle, i.e. A 0 , A . 1 , ......, A n-. 1- remaining under the category modulus n (prime number) Significance
And A n- , A n-+. 1 , ......, A 2N. 1- same residue class, so the answer must be in [0, n-1] within.
Values ​​of powers of p sense die to obtain a part, and store them up, and then the remaining portion of such evaluation is not possible to find a way of using a direct look-up table has been evaluated.
Order evaluation length m = ⌈√ P ⌉.
No evaluation section how to find, such as A m , ......  A 2 m - . 1 this section, if a solution, it must be A ⋅  A ≡  ( m O P ) of the case,
The A m to the right, into  A ≡  B '  ( m O P ),  B' = B · A - m . The Direct Access b ' have no corresponding answer i.
Thus, no portion of each segment can be evaluated to determine whether only one query solvable within the section.
A hash table to hold, x i is a number from I to i, A x minimum value of x, the insert query are O ( log n- ),
Achieve overall complexity O (√ n- log n- ).

Guess you like

Origin www.cnblogs.com/hhyx/p/12651045.html