You are viewing a single comment's thread. Return to all comments →
I tried to optimize the code and this was the result:
public static void print(int n){ if(n == 1){ System.out.println(2); return; } int i = 3; int count = 2; while(count < n){ i+=2; if(isPrime(i)) count++; } System.out.println(i); } public static boolean isPrime(int n){ if(n < 2) return false; if(n % 2 == 0 && n != 2) return false; for(int i = 3; i <= Math.sqrt(n); i+=2){ if(n % i == 0) return false; } return true; }
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #7: 10001st prime
You are viewing a single comment's thread. Return to all comments →
I tried to optimize the code and this was the result: