import numpy as np
from qiskit import Aer
from qiskit.algorithms import Shor
import matplotlib.pyplot as plt

x = np.linspace(start=0, stop=29, num=30)
plt.plot(x, (3**x) % 20, 'x--', linewidth=1)
plt.xlabel('x', fontsize=10)
plt.ylabel('$3^x$ mod 20', fontsize=10)
plt.grid(visible=True)
plt.show()

backend = Aer.get_backend('qasm_simulator')

shors = Shor(backend)
qc = shors.construct_circuit(N=3, measurement=True)
qc.draw()

shors.factor(N=3).factors

qc = shors.construct_circuit(N=15, measurement=True)
qc.draw()

shors.factor(N=15).factors

qc = shors.construct_circuit(N=35, measurement=True)
print('Number of qubits:', qc.num_qubits, '\nGate operations:', qc.size(), '\nDepth:', qc.depth())

shors.factor(N=35).factors