Euler Problem #7

Posted Thursday, April 17, 2008 9:46 PM by amarsan

Is it cheating to use the Matlab built in isprime function? It saves me from going to Google to find a prime number algorithm.

Here's my code:

function euler7

ii = 0;
jj = 2;
while 1
  if isprime(jj)
   ii=ii+1;
   if ii == 10001
    break;
   end
  end
  jj=jj+1;
end
jj

This completed in a reasonable amount of time on my slow Mac, but later I read about only testing odd numbers, and I wish I had thought of that.

Filed under:

Comments

No Comments

Leave a Comment

(required) 
(required) 
(optional)
(required)