Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Standard {
- public static void main(String[] Args) {
- int[] primeList = new int[1000000];
- int counter = 1;
- primeList[0] = 2;
- int toTest = 2;
- boolean isPrime = true;
- long time = System.currentTimeMillis();
- while(counter != 1000000) {
- toTest++;
- for(int i = 0; i<counter; i++) {
- if(toTest%primeList[i] == 0) {
- isPrime = false;
- break;
- }
- if(Math.ceil(toTest/2.0) < primeList[i]) break;
- }
- if(isPrime) {
- primeList[counter] = toTest;
- counter++;
- }
- isPrime = true;
- }
- System.out.println(System.currentTimeMillis() - time);
- // for(int i = 0; i<10000; i++) {
- // System.out.println(primeList[i]);
- // }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement