Refactor trial division into its own method.