



import timeit


class   lowerCamelCase__  :



 """simple docstring"""

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

 def __mul__(						self				:				Optional[Any] ,	__lowerCAmelCase				:				List[str]			)      ->  Dict:
    _A						     =					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   SCREAMING_SNAKE_CASE_       (  _snake_case  :List[str]  ,      _snake_case  :Optional[int]							)     ->    int:
   _A						     =					Matrix([[1, 0], [0, 1]]							)
   while b > 0:
      if b & 1:
         matrix *= a
      a *= a
      b >>= 1
   return matrix

def   SCREAMING_SNAKE_CASE_       (  _snake_case  :List[str]  ,      _snake_case  :str  ,      _snake_case  :Tuple							)     ->    Optional[Any]:
   # Trivial Cases
   if n == 1:
      return fa
   elif n == 2:
      return fa
   _A						     =					Matrix([[1, 1], [1, 0]]							)
   _A						     =					modular_exponentiation(_snake_case  ,      n - 2							)
   return fa * matrix.t[0][0] + fa * matrix.t[0][1]

def   SCREAMING_SNAKE_CASE_       (  _snake_case  :str  ,      _snake_case  :int  ,      _snake_case  :List[str]							)     ->    Union[str, Any]:
   # Trivial Cases
   if n == 1:
      return fa
   elif n == 2:
      return fa

   _A						     =					fa
   _A						     =					fa
   n -= 2

   while n > 0:
      _A     ,						_A						     =					fn_a + fn_a, fn_a
      n -= 1

   return fn_a

def   SCREAMING_SNAKE_CASE_       (  )     ->    Union[str, Any]:
   _A						     =					'''
from random import randint
from __main__ import fibonacci_with_matrix_exponentiation
'''
   _A						     =					'''fibonacci_with_matrix_exponentiation(randint(1,70000), 1, 1)'''
   _A						     =					timeit.timeit(setup=_snake_case  ,      stmt=_snake_case  ,      number=100							)
   print('''With matrix exponentiation the average execution time is '''  ,      exec_time / 100							)
   return exec_time

def   SCREAMING_SNAKE_CASE_       (  )     ->    Optional[int]:
   _A						     =					'''
from random import randint
from __main__ import simple_fibonacci
'''
   _A						     =					'''simple_fibonacci(randint(1,70000), 1, 1)'''
   _A						     =					timeit.timeit(setup=_snake_case  ,      stmt=_snake_case  ,      number=100							)
   print(
       '''Without matrix exponentiation the average execution time is '''  ,      exec_time / 100							)
   return exec_time

def   SCREAMING_SNAKE_CASE_       (  )     ->    Any:
   matrix_exponentiation_time()
   simple_fibonacci_time()


if __name__ == "__main__":
   main()








from __future__ import annotations

def   SCREAMING_SNAKE_CASE_       (  _snake_case  :int							)     ->    int | None:
   for r in range(1  ,      _snake_case							):
      _A						     =					[]
      for x in range(n - 1							):
         _A						     =					pow(_snake_case  ,      _snake_case  ,      _snake_case							)
         if val in li:
            break
         li.append(_snake_case							)
      else:
         return r
   return None


if __name__ == "__main__":
   UpperCAmelCase_		   =				int(input("""Enter a prime number q: """))
   UpperCAmelCase_		   =				find_primitive(q)
   if a is None:
      print(f'Cannot find the primitive for the value: {a!r}')
   else:
      UpperCAmelCase_		   =				int(input("""Enter private key of A: """))
      UpperCAmelCase_		   =				pow(a, a_private, q)
      UpperCAmelCase_		   =				int(input("""Enter private key of B: """))
      UpperCAmelCase_		   =				pow(a, b_private, q)

      UpperCAmelCase_		   =				pow(b_public, a_private, q)
      UpperCAmelCase_		   =				pow(a_public, b_private, q)

      print("""The key value generated by A is: """, a_secret)
      print("""The key value generated by B is: """, b_secret)



