
"""simple docstring"""



import math

import qiskit
def 					_UpperCAmelCase      ( __lowerCamelCase   :       int = 1 ,					__lowerCamelCase   :       int = 1 ,					__lowerCamelCase   :       int = 1		)     ->					qiskit.result.counts.Counts:
  if (
      isinstance(__lowerCamelCase ,					__lowerCamelCase		)
      or isinstance(__lowerCamelCase ,					__lowerCamelCase		)
      or isinstance(__lowerCamelCase ,					__lowerCamelCase		)
  ):
    raise TypeError('''inputs must be integers.'''		)

  if (input_a < 0) or (input_a < 0) or (carry_in < 0):
    raise ValueError('''inputs must be positive.'''		)

  if (
      (math.floor(__lowerCamelCase		) != input_a)
      or (math.floor(__lowerCamelCase		) != input_a)
      or (math.floor(__lowerCamelCase		) != carry_in)
  ):
    raise ValueError('''inputs must be exact integers.'''		)

  if (input_a > 2) or (input_a > 2) or (carry_in > 2):
    raise ValueError('''inputs must be less or equal to 2.'''		)

  # build registers
  _snake_case					     =       qiskit.QuantumRegister(4 ,					'''qr'''		)
  _snake_case					     =       qiskit.ClassicalRegister(2 ,					'''cr'''		)
  # list the entries
  _snake_case					     =       [input_a, input_a, carry_in]

  _snake_case					     =       qiskit.QuantumCircuit(__lowerCamelCase ,					__lowerCamelCase		)

  for i in range(0 ,					3		):
    if entry[i] == 2:
      quantum_circuit.h(__lowerCamelCase		)  # for hadamard entries
    elif entry[i] == 1:
      quantum_circuit.x(__lowerCamelCase		)  # for 1 entries
    elif entry[i] == 0:
      quantum_circuit.i(__lowerCamelCase		)  # for 0 entries

    # build the circuit
  quantum_circuit.ccx(0 ,					1 ,					3		)  # ccx = toffoli gate
  quantum_circuit.cx(0 ,					1		)
  quantum_circuit.ccx(1 ,					2 ,					3		)
  quantum_circuit.cx(1 ,					2		)
  quantum_circuit.cx(0 ,					1		)

  quantum_circuit.measure([2, 3] ,					__lowerCamelCase		)  # measure the last two qbits

  _snake_case					     =       qiskit.Aer.get_backend('''aer_simulator'''		)
  _snake_case					     =       qiskit.execute(__lowerCamelCase ,					__lowerCamelCase ,					shots=10_00		)

  return job.result().get_counts(__lowerCamelCase		)


if __name__ == "__main__":
 print(F"Total sum count for state is: {quantum_full_adder(1, 1, 1)}")





"""simple docstring"""



from math import pow
def 					_UpperCAmelCase      ( __lowerCamelCase   :       int ,					__lowerCamelCase   :       int ,					__lowerCamelCase   :       int ,					__lowerCamelCase   :       int ,					__lowerCamelCase   :       int ,					)     ->					tuple[int, int]:
  if current_sum == needed_sum:
    # If the sum of the powers is equal to needed_sum, then we have a solution.
    solutions_count += 1
    return current_sum, solutions_count

  _snake_case					     =       int(pow(__lowerCamelCase ,					__lowerCamelCase		)		)
  if current_sum + i_to_n <= needed_sum:
    # If the sum of the powers is less than needed_sum, then continue adding powers.
    current_sum += i_to_n
    _snake_case     ,					_snake_case					     =       backtrack(
        __lowerCamelCase ,					__lowerCamelCase ,					current_number + 1 ,					__lowerCamelCase ,					__lowerCamelCase		)
    current_sum -= i_to_n
  if i_to_n < needed_sum:
    # If the power of i is less than needed_sum, then try with the next power.
    _snake_case     ,					_snake_case					     =       backtrack(
        __lowerCamelCase ,					__lowerCamelCase ,					current_number + 1 ,					__lowerCamelCase ,					__lowerCamelCase		)
  return current_sum, solutions_count
def 					_UpperCAmelCase      ( __lowerCamelCase   :       int ,					__lowerCamelCase   :       int		)     ->					int:
  if not (1 <= needed_sum <= 10_00 and 2 <= power <= 10):
    raise ValueError(
        '''Invalid input\n'''
        '''needed_sum must be between 1 and 1000, power between 2 and 10.'''		)

  return backtrack(__lowerCamelCase ,					__lowerCamelCase ,					1 ,					0 ,					0		)[1]  # Return the solutions_count


if __name__ == "__main__":
 import doctest

 doctest.testmod()



