Skip to main content
1 of 2
nickjamesuk
  • 883
  • 6
  • 13

Making Mathematica more lazy

I want to find the first 5 prime numbers of the form n^6 + 1091. I have used this code:

 Timing[Select[Table[n^6 + 1091, {n, 10000}], PrimeQ, 5]] 

Which gives the desired answer, and takes 0.0156 seconds. What if I didn't have a rough idea of what values of n to check?

Timing[Select[Table[n^6 + 1091, {n, 100000}], PrimeQ, 5]] 

Takes 10 times as long.

So, my question is: Is there a simple(ish) way to make Mathematica stop when the desired number of solutions are found?

nickjamesuk
  • 883
  • 6
  • 13