code: 
  
  import numpy as np
  import qiskit
  
  
  
  def  _A  (			SCREAMING_SNAKE_CASE  ,SCREAMING_SNAKE_CASE			):
  	UpperCAmelCase__:  List[Any]		       =   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:
  		UpperCAmelCase__:  Any		       =   np.random.randint(1  ,2**num_qubits			)
  		# Next, format 'b' as a binary string of length 'n', padded with zeros:
  		UpperCAmelCase__:  Tuple		       =   format(lowerCAmelCase__  ,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(lowerCAmelCase__			):
  			if bit == "1":
  				oracle_qc.x(lowerCAmelCase__			)
          # Do the controlled-NOT gates for each qubit, using the output qubit
          # as the target:
  		for index in range(lowerCAmelCase__			):
  			oracle_qc.cx(lowerCAmelCase__  ,lowerCAmelCase__			)
  		# Next, place the final X-gates
  		for index, bit in enumerate(lowerCAmelCase__			):
  			if bit == "1":
  				oracle_qc.x(lowerCAmelCase__			)
  
      # 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)
  		UpperCAmelCase__:  Dict		       =   np.random.randint(2			)
  		if output == 1:
  			oracle_qc.x(lowerCAmelCase__			)
  
  	UpperCAmelCase__:  Optional[int]		       =   oracle_qc.to_gate()
  	UpperCAmelCase__:  str		       =   'Oracle'  # To show when we display the circuit
  	return oracle_gate
  
  
  
  def  _A  (			SCREAMING_SNAKE_CASE  ,SCREAMING_SNAKE_CASE			):
  	UpperCAmelCase__:  int		       =   qiskit.QuantumCircuit(num_qubits + 1  ,lowerCAmelCase__			)
  	# Set up the output qubit:
  	dj_circuit.x(lowerCAmelCase__			)
  	dj_circuit.h(lowerCAmelCase__			)
  	# And set up the input register:
  	for qubit in range(lowerCAmelCase__			):
  		dj_circuit.h(lowerCAmelCase__			)
  	# Let's append the oracle gate to our circuit:
  	dj_circuit.append(lowerCAmelCase__  ,range(num_qubits + 1			)			)
  	# Finally, perform the H-gates again and measure:
  	for qubit in range(lowerCAmelCase__			):
  		dj_circuit.h(lowerCAmelCase__			)
  
  	for i in range(lowerCAmelCase__			):
  		dj_circuit.measure(lowerCAmelCase__  ,lowerCAmelCase__			)
  
  	return dj_circuit
  
  
  
  def  _A  (			SCREAMING_SNAKE_CASE  ,SCREAMING_SNAKE_CASE			):
  	UpperCAmelCase__:  Any		       =   qiskit.Aer.get_backend("aer_simulator"			)
  
  	UpperCAmelCase__:  Dict		       =   dj_oracle(lowerCAmelCase__  ,lowerCAmelCase__			)
  	UpperCAmelCase__:  Optional[int]		       =   dj_algorithm(lowerCAmelCase__  ,lowerCAmelCase__			)
  
  	# Execute the circuit on the simulator
  	UpperCAmelCase__:  Any		       =   qiskit.execute(lowerCAmelCase__  ,lowerCAmelCase__  ,shots=1_0_0_0			)
  
  	# Return the histogram data of the results of the experiment.
  	return job.result().get_counts(lowerCAmelCase__			)
  
  
  if __name__ == "__main__":
  			print(F"Deutsch Jozsa - Constant Oracle: {deutsch_jozsa('constant', 3)}")
  			print(F"Deutsch Jozsa - Balanced Oracle: {deutsch_jozsa('balanced', 3)}")
style_context: 
  
  from __future__ import annotations
  
  
  
  def  _A  (			SCREAMING_SNAKE_CASE  ,SCREAMING_SNAKE_CASE  ,SCREAMING_SNAKE_CASE			):
  	assert n > 1 and a > 0 and greatest_common_divisor(SCREAMING_SNAKE_CASE  ,SCREAMING_SNAKE_CASE			) == 1
  	((UpperCAmelCase__)       ,	(UpperCAmelCase__)       ,	(UpperCAmelCase__)):  Optional[Any]		       =   extended_gcd(SCREAMING_SNAKE_CASE  ,SCREAMING_SNAKE_CASE			)  # Implemented below
  	UpperCAmelCase__:  List[str]		       =   (b * s) % n
  	return x
  
  
  
  def  _A  (			SCREAMING_SNAKE_CASE  ,SCREAMING_SNAKE_CASE			):
  	((UpperCAmelCase__)       ,	(UpperCAmelCase__)):  int		       =   extended_euclid(SCREAMING_SNAKE_CASE  ,SCREAMING_SNAKE_CASE			)  # Implemented below
  	if b < 0:
  		UpperCAmelCase__:  List[str]		       =   (b % n + n) % n
  	return b
  
  
  
  def  _A  (			SCREAMING_SNAKE_CASE  ,SCREAMING_SNAKE_CASE  ,SCREAMING_SNAKE_CASE			):
  	UpperCAmelCase__:  Union[str, Any]		       =   invert_modulo(SCREAMING_SNAKE_CASE  ,SCREAMING_SNAKE_CASE			)
  	UpperCAmelCase__:  Any		       =   (b * s) % n
  	return x
  
  
  
  def  _A  (			SCREAMING_SNAKE_CASE  ,SCREAMING_SNAKE_CASE			):
  	assert a >= 0 and b >= 0
  
  	if b == 0:
  		UpperCAmelCase__       ,	UpperCAmelCase__       ,	UpperCAmelCase__:  List[Any]		       =   a, 1, 0
  	else:
  		((UpperCAmelCase__)       ,	(UpperCAmelCase__)       ,	(UpperCAmelCase__)):  Tuple		       =   extended_gcd(SCREAMING_SNAKE_CASE  ,a % b			)
  		UpperCAmelCase__:  Union[str, Any]		       =   q
  		UpperCAmelCase__:  Union[str, Any]		       =   p - q * (a // b)
  
  	assert a % d == 0 and b % d == 0
  	assert d == a * x + b * y
  
  	return (d, x, y)
  
  
  
  def  _A  (			SCREAMING_SNAKE_CASE  ,SCREAMING_SNAKE_CASE			):
  	if b == 0:
  		return (1, 0)
  	((UpperCAmelCase__)       ,	(UpperCAmelCase__)):  List[str]		       =   extended_euclid(SCREAMING_SNAKE_CASE  ,a % b			)
  	UpperCAmelCase__:  Optional[Any]		       =   a // b
  	return (y, x - k * y)
  
  
  
  def  _A  (			SCREAMING_SNAKE_CASE  ,SCREAMING_SNAKE_CASE			):
  	if a < b:
  		UpperCAmelCase__       ,	UpperCAmelCase__:  str		       =   b, a
  
  	while a % b != 0:
  		UpperCAmelCase__       ,	UpperCAmelCase__:  Union[str, Any]		       =   b, a % b
  
  	return b
  
  
  if __name__ == "__main__":
  					from doctest import testmod
  
  					testmod(name="""modular_division""", verbose=True)
  					testmod(name="""modular_division2""", verbose=True)
  					testmod(name="""invert_modulo""", verbose=True)
  					testmod(name="""extended_gcd""", verbose=True)
  					testmod(name="""extended_euclid""", verbose=True)
  					testmod(name="""greatest_common_divisor""", verbose=True)