





'''simple docstring'''
def 				lowercase__   (   __lowercase						:  Union[str, Any]				,  __lowercase						:  List[Any]				,  __lowercase						:  Optional[int]     ) ->      Any:



       """simple docstring"""






       if n == 0:
              return 1

       elif n % 2 == 1:
              return (binary_exponentiation(__lowercase				,  n - 1				,  __lowercase     ) * a) % mod

       else:
              __UpperCamelCase       =  binary_exponentiation(__lowercase				,  n / 2				,  __lowercase     )
              return (b * b) % mod


# a prime number
a__							:							Tuple =701

a__							:							Union[str, Any] =1_000_000_000
a__							:							List[Any] =10

# using binary exponentiation function, O(log(p)):
print((a / b) % p == (a * binary_exponentiation(b, p - 2, p)) % p)


print((a / b) % p == (a * b ** (p - 2)) % p)







'''simple docstring'''
a__							:							Optional[Any] =256
# Modulus to hash a string
a__							:							Dict =1_000_003
def 				lowercase__   (   __lowercase						:  str				,  __lowercase						:  str     ) ->      bool:



       """simple docstring"""






       __UpperCamelCase       =  len(__lowercase     )
       __UpperCamelCase       =  len(__lowercase     )
       if p_len > t_len:
              return False

       __UpperCamelCase       =  0
       __UpperCamelCase       =  0
       __UpperCamelCase       =  1

       # Calculating the hash of pattern and substring of text
       for i in range(__lowercase     ):
              __UpperCamelCase       =  (ord(pattern[i]     ) + p_hash * alphabet_size) % modulus
              __UpperCamelCase       =  (ord(text[i]     ) + text_hash * alphabet_size) % modulus
              if i == p_len - 1:
                     continue
              __UpperCamelCase       =  (modulus_power * alphabet_size) % modulus

       for i in range(0				,  t_len - p_len + 1     ):
              if text_hash == p_hash and text[i : i + p_len] == pattern:
                     return True
              if i == t_len - p_len:
                     continue
              # Calculate the https://en.wikipedia.org/wiki/Rolling_hash
              __UpperCamelCase       =  (
                  (text_hash - ord(text[i]     ) * modulus_power) * alphabet_size
                  + ord(text[i + p_len]     )
              ) % modulus
       return False
def 				lowercase__   (   ) ->      None:



       """simple docstring"""






       __UpperCamelCase       =  'abc1abc12'
       __UpperCamelCase       =  'alskfjaldsabc1abc1abc12k23adsfabcabc'
       __UpperCamelCase       =  'alskfjaldsk23adsfabcabc'
       assert rabin_karp(__lowercase				,  __lowercase     ) and not rabin_karp(__lowercase				,  __lowercase     )

       # Test 2)
       __UpperCamelCase       =  'ABABX'
       __UpperCamelCase       =  'ABABZABABYABABX'
       assert rabin_karp(__lowercase				,  __lowercase     )

       # Test 3)
       __UpperCamelCase       =  'AAAB'
       __UpperCamelCase       =  'ABAAAAAB'
       assert rabin_karp(__lowercase				,  __lowercase     )

       # Test 4)
       __UpperCamelCase       =  'abcdabcy'
       __UpperCamelCase       =  'abcxabcdabxabcdabcdabcy'
       assert rabin_karp(__lowercase				,  __lowercase     )

       # Test 5)
       __UpperCamelCase       =  'Lü'
       __UpperCamelCase       =  'Lüsai'
       assert rabin_karp(__lowercase				,  __lowercase     )
       __UpperCamelCase       =  'Lue'
       assert not rabin_karp(__lowercase				,  __lowercase     )
       print('Success.'     )


if __name__ == "__main__":
    test_rabin_karp()
