The algorithm is based on this Mathoverflow question.
If the "sequential" option is checked, the program will print all the result for values of p up to your input.