






"""simple docstring"""





from .hash_table import HashTable
from .number_theory.prime_numbers import is_prime, next_prime







class 						_a  (		lowercase_       ):





   '''simple docstring'''






   def __init__(       self					, *UpperCAmelCase_					, **UpperCAmelCase_)			->   Tuple:




          '''simple docstring'''




          super().__init__(*UpperCAmelCase_					, **UpperCAmelCase_)





   def __lowercase							(       self					, UpperCAmelCase_					, UpperCAmelCase_)			->   Dict:




          '''simple docstring'''




          lowercase__:							Union[str, Any]         =     (
              next_prime(value % self.size_table)
              if not is_prime(value % self.size_table)
              else value % self.size_table
          )  # gt = bigger than
          return next_prime_gt - (data % next_prime_gt)





   def __lowercase							(       self					, UpperCAmelCase_					, UpperCAmelCase_					, UpperCAmelCase_)			->   Union[str, Any]:




          '''simple docstring'''




          return (increment * self.__hash_function_a(UpperCAmelCase_					, UpperCAmelCase_)) % self.size_table





   def __lowercase							(       self					, UpperCAmelCase_					, UpperCAmelCase_=None)			->   Union[str, Any]:




          '''simple docstring'''




          lowercase__:							str         =     1
          lowercase__:							List[str]         =     self.hash_function(UpperCAmelCase_)

          while self.values[new_key] is not None and self.values[new_key] != key:
                 lowercase__:							int         =     (
                     self.__hash_double_function(UpperCAmelCase_					, UpperCAmelCase_					, UpperCAmelCase_)
                     if self.balanced_factor() >= self.lim_charge
                     else None
                 )
                 if new_key is None:
                        break
                 else:
                        i += 1

          return new_key













'''simple docstring'''






import timeit


class 	_lowercase    :


   def __init__(			self     , _UpperCAmelCase       ):
       if isinstance(_UpperCAmelCase     , _UpperCAmelCase       ):  # Initializes a matrix identical to the one provided.
           A							:							List[Any]				=    arg
           A							:							Dict				=    len(_UpperCAmelCase       )
       else:  # Initializes a square matrix of the given size and set values to zero.
           A							:							str				=    arg
           A							:							Union[str, Any]				=    [[0 for _ in range(self.n       )] for _ in range(self.n       )]


   def __mul__(			self     , _UpperCAmelCase       ):
       A							:							List[str]				=    Matrix(self.n       )
       for i in range(self.n       ):
           for j in range(self.n       ):
               for k in range(self.n       ):
                   matrix.t[i][j] += self.t[i][k] * b.t[k][j]
       return matrix







def 				_lowerCamelCase(	UpperCamelCase__     :			Union[str, Any]     ,							UpperCamelCase__     :			int		)		->	Union[str, Any]:
    A							:							Tuple				=    Matrix([[1, 0], [0, 1]]		)
    while b > 0:
        if b & 1:
            matrix *= a
        a *= a
        b >>= 1
    return matrix
def 				_lowerCamelCase(	UpperCamelCase__     :			int     ,							UpperCamelCase__     :			Tuple     ,							UpperCamelCase__     :			Any		)		->	Any:
    # Trivial Cases
    if n == 1:
        return fa
    elif n == 2:
        return fa
    A							:							Optional[Any]				=    Matrix([[1, 1], [1, 0]]		)
    A							:							int				=    modular_exponentiation(UpperCamelCase__     ,							n - 2		)
    return fa * matrix.t[0][0] + fa * matrix.t[0][1]
def 				_lowerCamelCase(	UpperCamelCase__     :			str     ,							UpperCamelCase__     :			Optional[Any]     ,							UpperCamelCase__     :			Any		)		->	List[Any]:
    # Trivial Cases
    if n == 1:
        return fa
    elif n == 2:
        return fa

    A							:							str				=    fa
    A							:							List[Any]				=    fa
    n -= 2

    while n > 0:
        A,						A							:							List[str]				=    fn_a + fn_a, fn_a
        n -= 1

    return fn_a
def 				_lowerCamelCase(	)		->	Union[str, Any]:
    A							:							Any				=    '''
from random import randint
from __main__ import fibonacci_with_matrix_exponentiation
'''
    A							:							Optional[int]				=    '''fibonacci_with_matrix_exponentiation(randint(1,70000), 1, 1)'''
    A							:							List[Any]				=    timeit.timeit(setup=UpperCamelCase__     ,							stmt=UpperCamelCase__     ,							number=100		)
    print('''With matrix exponentiation the average execution time is '''     ,							exec_time / 100		)
    return exec_time
def 				_lowerCamelCase(	)		->	List[Any]:
    A							:							str				=    '''
from random import randint
from __main__ import simple_fibonacci
'''
    A							:							Any				=    '''simple_fibonacci(randint(1,70000), 1, 1)'''
    A							:							str				=    timeit.timeit(setup=UpperCamelCase__     ,							stmt=UpperCamelCase__     ,							number=100		)
    print(
        '''Without matrix exponentiation the average execution time is '''     ,							exec_time / 100		)
    return exec_time
def 				_lowerCamelCase(	)		->	Optional[Any]:
    matrix_exponentiation_time()
    simple_fibonacci_time()


if __name__ == "__main__":
     main()
