




'''simple docstring'''







import numpy as np
import qiskit






def 						_lowercase						(      lowercase_		,				lowercase_    ):



		'''simple docstring'''







		_snake_case      			=			qiskit.QuantumCircuit(num_qubits + 1    )

		# First, let's deal with the case in which oracle is balanced
		if case == "balanced":
				# First generate a random number that tells us which CNOTs to
				# wrap in X-gates:
				_snake_case      			=			np.random.randint(1		,				2**num_qubits    )
				# Next, format 'b' as a binary string of length 'n', padded with zeros:
				_snake_case      			=			format(_SCREAMING_SNAKE_CASE		,				f'''0{num_qubits}b'''    )
				# Next, we place the first X-gates. Each digit in our binary string
				# corresponds to a qubit, if the digit is 0, we do nothing, if it's 1
				# we apply an X-gate to that qubit:
				for index, bit in enumerate(_SCREAMING_SNAKE_CASE    ):
						if bit == "1":
								oracle_qc.x(_SCREAMING_SNAKE_CASE    )
        # Do the controlled-NOT gates for each qubit, using the output qubit
        # as the target:
				for index in range(_SCREAMING_SNAKE_CASE    ):
						oracle_qc.cx(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE    )
				# Next, place the final X-gates
				for index, bit in enumerate(_SCREAMING_SNAKE_CASE    ):
						if bit == "1":
								oracle_qc.x(_SCREAMING_SNAKE_CASE    )

    # Case in which oracle is constant
		if case == "constant":
				# First decide what the fixed output of the oracle will be
				# (either always 0 or always 1)
				_snake_case      			=			np.random.randint(2    )
				if output == 1:
						oracle_qc.x(_SCREAMING_SNAKE_CASE    )

		_snake_case      			=			oracle_qc.to_gate()
		_snake_case      			=			"Oracle"  # To show when we display the circuit
		return oracle_gate






def 						_lowercase						(      lowercase_		,				lowercase_    ):



		'''simple docstring'''







		_snake_case      			=			qiskit.QuantumCircuit(num_qubits + 1		,				_SCREAMING_SNAKE_CASE    )
		# Set up the output qubit:
		dj_circuit.x(_SCREAMING_SNAKE_CASE    )
		dj_circuit.h(_SCREAMING_SNAKE_CASE    )
		# And set up the input register:
		for qubit in range(_SCREAMING_SNAKE_CASE    ):
				dj_circuit.h(_SCREAMING_SNAKE_CASE    )
		# Let's append the oracle gate to our circuit:
		dj_circuit.append(_SCREAMING_SNAKE_CASE		,				range(num_qubits + 1    )    )
		# Finally, perform the H-gates again and measure:
		for qubit in range(_SCREAMING_SNAKE_CASE    ):
				dj_circuit.h(_SCREAMING_SNAKE_CASE    )

		for i in range(_SCREAMING_SNAKE_CASE    ):
				dj_circuit.measure(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE    )

		return dj_circuit






def 						_lowercase						(      lowercase_		,				lowercase_    ):



		'''simple docstring'''







		_snake_case      			=			qiskit.Aer.get_backend("aer_simulator"    )

		_snake_case      			=			dj_oracle(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE    )
		_snake_case      			=			dj_algorithm(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE    )

		# Execute the circuit on the simulator
		_snake_case      			=			qiskit.execute(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				shots=1000    )

		# Return the histogram data of the results of the experiment.
		return job.result().get_counts(_SCREAMING_SNAKE_CASE    )


if __name__ == "__main__":
						print(F'''Deutsch Jozsa - Constant Oracle: {deutsch_jozsa('constant', 3)}''')
						print(F'''Deutsch Jozsa - Balanced Oracle: {deutsch_jozsa('balanced', 3)}''')










import math
def 				UpperCAmelCase__		(					_SCREAMING_SNAKE_CASE :						int					)->bool:

      if 1 < number < 4:
            # 2 and 3 are primes
            return True
      elif number < 2 or number % 2 == 0 or number % 3 == 0:
            # Negatives, 0, 1, all even numbers, all multiples of 3 are not primes
            return False

      # All primes number are in format of 6k +/- 1
      for i in range(5  ,					int(math.sqrt(_SCREAMING_SNAKE_CASE					) + 1					)  ,					6					):
            if number % i == 0 or number % (i + 2) == 0:
                  return False
      return True
def 				UpperCAmelCase__		(					_SCREAMING_SNAKE_CASE :						int = 6_0_0_8_5_1_4_7_5_1_4_3					)->int:

      try:
            _lowerCAmelCase			      =	int(_SCREAMING_SNAKE_CASE					)
      except (TypeError, ValueError):
            raise TypeError('''Parameter n must be int or castable to int.'''					)
      if n <= 0:
            raise ValueError('''Parameter n must be greater than or equal to one.'''					)
      _lowerCAmelCase			      =	0
      if is_prime(_SCREAMING_SNAKE_CASE					):
            return n
      while n % 2 == 0:
            n //= 2
      if is_prime(_SCREAMING_SNAKE_CASE					):
            return n
      for i in range(3  ,					int(math.sqrt(_SCREAMING_SNAKE_CASE					)					) + 1  ,					2					):
            if n % i == 0:
                  if is_prime(n // i					):
                        _lowerCAmelCase			      =	n // i
                        break
                  elif is_prime(_SCREAMING_SNAKE_CASE					):
                        _lowerCAmelCase			      =	i
      return max_number


if __name__ == "__main__":
    print(F"""{solution() = }""")