Ti conviene cercare "algoritmo AKS" perchè, anche se è complicato, garantisce alte prestazioni soprattutto con un input elevato.