





import qiskit
from qiskit.providers import Backend






def 				_lowerCAmelCase			(	_a :       int       , _a :       int      )						->      tuple[qiskit.QuantumCircuit, str, str]:
     lowerCAmelCase_ ,	lowerCAmelCase_       :							Optional[int]			 =		bin(UpperCAmelCase_      )[2:], bin(UpperCAmelCase_      )[2:]  # Remove leading '0b'

     # Ensure that both strings are of the same length
     if len(UpperCAmelCase_      ) > len(UpperCAmelCase_      ):
          lowerCAmelCase_       :							Optional[Any]			 =		y.zfill(len(UpperCAmelCase_      )      )
     else:
          lowerCAmelCase_       :							Dict			 =		x.zfill(len(UpperCAmelCase_      )      )

     # 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
     lowerCAmelCase_       :							Tuple			 =		qiskit.QuantumCircuit((len(UpperCAmelCase_      ) * 3) + 1       , len(UpperCAmelCase_      ) + 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(UpperCAmelCase_      )      ):
          if x[::-1][i] == "1":
               circuit.x(UpperCAmelCase_      )
     for j in range(len(UpperCAmelCase_      )      ):
          if y[::-1][j] == "1":
               circuit.x(len(UpperCAmelCase_      ) + j      )

     return circuit, x, y






def 				_lowerCAmelCase			(	_a :       qiskit.QuantumCircuit       , _a :       int       , _a :       int       , _a :       int       , _a :       int       , )						->      Any:
     circuit.ccx(UpperCAmelCase_       , UpperCAmelCase_       , UpperCAmelCase_      )
     circuit.cx(UpperCAmelCase_       , UpperCAmelCase_      )
     circuit.ccx(UpperCAmelCase_       , UpperCAmelCase_       , UpperCAmelCase_      )
     circuit.cx(UpperCAmelCase_       , UpperCAmelCase_      )
     circuit.cx(UpperCAmelCase_       , UpperCAmelCase_      )






def 				_lowerCAmelCase			(	_a :       int       , _a :       int       , _a :       Backend = qiskit.Aer.get_backend("""aer_simulator"""      )       , )						->      int:




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

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

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

     lowerCAmelCase_       :							Dict			 =		qiskit.execute(UpperCAmelCase_       , UpperCAmelCase_       , 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()






import math
from timeit import timeit





def 							lowerCamelCase    (							UpperCAmelCase_	:      int      )->			int:

       """simple docstring"""




       a			   =0
       a			   =abs(UpperCAmelCase_      )
       while True:
              a			   =n // 10
              digits += 1
              if n == 0:
                     break
       return digits





def 							lowerCamelCase    (							UpperCAmelCase_	:      int      )->			int:

       """simple docstring"""




       return 1 if n == 0 else math.floor(math.log(abs(UpperCAmelCase_      )   ,       10      ) + 1      )





def 							lowerCamelCase    (							UpperCAmelCase_	:      int      )->			int:

       """simple docstring"""




       return len(str(abs(UpperCAmelCase_      )      )      )





def 							lowerCamelCase    (							)->			None:

       """simple docstring"""




       from collections.abc import Callable

       def benchmark_a_function(UpperCAmelCase_	:      Callable   ,       UpperCAmelCase_	:      int      ) -> None:
              a			   =F'''{func.__name__}({value})'''
              a			   =timeit(F'''__main__.{call}'''   ,       setup="""import __main__"""      )
              print(F'''{call}: {func(UpperCAmelCase_      )} -- {timing} seconds'''      )

       for value in (26_2144, 1125_8999_0684_2624, 126_7650_6002_2822_9401_4967_0320_5376):
              for func in (num_digits, num_digits_fast, num_digits_faster):
                     benchmark_a_function(UpperCAmelCase_   ,       UpperCAmelCase_      )
              print()


if __name__ == "__main__":
    import doctest

    doctest.testmod()
    benchmark()
