Math.Modulus.Log
logMod :: Int -> Int -> Int -> Maybe Int Source #
Baby-step Giant-step
a^x = b (mod p) p is prime
a^x = b (mod p)
O(sqrt P * log P)
>>> logMod 3 27 998244353 Just 3 >>> logMod 3 123456789 998244353 Just 772453214 >>> logMod 1 2 1000000007 Nothing
>>>
logMod 3 27 998244353
logMod 3 123456789 998244353
logMod 1 2 1000000007