

import timeit







class 							a__							:







  """simple docstring"""




  def __init__(      self     :			Optional[int]					,					UpperCAmelCase__     :			Any		)       ->Tuple:
        """simple docstring"""







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




  def __mul__(      self     :			Optional[Any]					,					UpperCAmelCase__     :			Optional[int]		)       ->Optional[Any]:
        """simple docstring"""







        SCREAMING_SNAKE_CASE			:   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        __lowercase   (  _A    ,     _A      )  ->    List[Any]:
      SCREAMING_SNAKE_CASE			:   List[str]	  = Matrix([[1, 0], [0, 1]]      )
      while b > 0:
            if b & 1:
                  matrix *= a
            a *= a
            b >>= 1
      return matrix






def        __lowercase   (  _A    ,     _A    ,     _A      )  ->    Dict:



      if n == 1:
            return fa
      elif n == 2:
            return fa
      SCREAMING_SNAKE_CASE			:   Tuple	  = Matrix([[1, 1], [1, 0]]      )
      SCREAMING_SNAKE_CASE			:   str	  = modular_exponentiation(_A    ,     n - 2      )
      return fa * matrix.t[0][0] + fa * matrix.t[0][1]






def        __lowercase   (  _A    ,     _A    ,     _A      )  ->    Optional[int]:



      if n == 1:
            return fa
      elif n == 2:
            return fa

      SCREAMING_SNAKE_CASE			:   Optional[int]	  = fa
      SCREAMING_SNAKE_CASE			:   Optional[Any]	  = fa
      n -= 2

      while n > 0:
            SCREAMING_SNAKE_CASE  ,						SCREAMING_SNAKE_CASE			:   Tuple	  = fn_a + fn_a, fn_a
            n -= 1

      return fn_a






def        __lowercase   (  )  ->    List[str]:
      SCREAMING_SNAKE_CASE			:   str	  = """\nfrom random import randint\nfrom __main__ import fibonacci_with_matrix_exponentiation\n"""
      SCREAMING_SNAKE_CASE			:   Any	  = """fibonacci_with_matrix_exponentiation(randint(1,70000), 1, 1)"""
      SCREAMING_SNAKE_CASE			:   List[str]	  = timeit.timeit(setup=_A    ,     stmt=_A    ,     number=100      )
      print("""With matrix exponentiation the average execution time is """    ,     exec_time / 100      )
      return exec_time






def        __lowercase   (  )  ->    int:
      SCREAMING_SNAKE_CASE			:   Dict	  = """\nfrom random import randint\nfrom __main__ import simple_fibonacci\n"""
      SCREAMING_SNAKE_CASE			:   Tuple	  = """simple_fibonacci(randint(1,70000), 1, 1)"""
      SCREAMING_SNAKE_CASE			:   Optional[Any]	  = timeit.timeit(setup=_A    ,     stmt=_A    ,     number=100      )
      print(
          """Without matrix exponentiation the average execution time is """    ,     exec_time / 100      )
      return exec_time






def        __lowercase   (  )  ->    Dict:
      matrix_exponentiation_time()
      simple_fibonacci_time()


if __name__ == "__main__":
  main()





"""simple docstring"""


import qiskit
from qiskit.providers import Backend







def        __a (		A     ,					A   ):






     '''simple docstring'''



     lowercase__			,    lowercase__								=				bin(A   )[2:], bin(A   )[2:]  # Remove leading '0b'

     # Ensure that both strings are of the same length
     if len(A   ) > len(A   ):
          lowercase__								=				y.zfill(len(A   )   )
     else:
          lowercase__								=				x.zfill(len(A   )   )

     # We need (3 * number of bits in the larger number)+1 qBits
     # The second parameter is the number of classical registers, to measure the result
     lowercase__								=				qiskit.QuantumCircuit((len(A   ) * 3) + 1     ,					len(A   ) + 1   )

     # We are essentially "not-ing" the bits that are 1
     # Reversed because it's easier to perform ops on more significant bits
     for i in range(len(A   )   ):
          if x[::-1][i] == "1":
               circuit.x(A   )
     for j in range(len(A   )   ):
          if y[::-1][j] == "1":
               circuit.x(len(A   ) + j   )

     return circuit, x, y







def        __a (		A     ,					A     ,					A     ,					A     ,					A     ,					):






     '''simple docstring'''



     circuit.ccx(A     ,					A     ,					A   )
     circuit.cx(A     ,					A   )
     circuit.ccx(A     ,					A     ,					A   )
     circuit.cx(A     ,					A   )
     circuit.cx(A     ,					A   )







def        __a (		A     ,					A     ,					A = qiskit.Aer.get_backend("aer_simulator"   )     ,					):






     '''simple docstring'''



     if vala < 0 or vala < 0:
          raise ValueError("Both Integers must be positive!"   )

     # Store the Integers
     lowercase__			,    lowercase__			,    lowercase__								=				store_two_classics(A     ,					A   )
     for i in range(len(A   )   ):
          full_adder(A     ,					A     ,					len(A   ) + i     ,					len(A   ) + len(A   ) + i     ,					len(A   ) + len(A   ) + i + 1   )
          circuit.barrier()  # Optional, just for aesthetics

     # Measure the resultant qBits
     for i in range(len(A   ) + 1   ):
          circuit.measure([(len(A   ) * 2) + i]     ,					[i]   )

     lowercase__								=				qiskit.execute(A     ,					A     ,					shots=1   ).result()

     # The result is in binary. Convert it back to int
     return int(list(res.get_counts()   )[0]     ,					2   )


if __name__ == "__main__":
 import doctest

 doctest.testmod()




