Advertisement
Guest User

Untitled

a guest
Jul 25th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. public class Standard {
  2. public static void main(String[] Args) {
  3. int[] primeList = new int[1000000];
  4. int counter = 1;
  5. primeList[0] = 2;
  6. int toTest = 2;
  7. boolean isPrime = true;
  8. long time = System.currentTimeMillis();
  9. while(counter != 1000000) {
  10. toTest++;
  11. for(int i = 0; i<counter; i++) {
  12. if(toTest%primeList[i] == 0) {
  13. isPrime = false;
  14. break;
  15. }
  16. if(Math.ceil(toTest/2.0) < primeList[i]) break;
  17. }
  18. if(isPrime) {
  19. primeList[counter] = toTest;
  20. counter++;
  21. }
  22. isPrime = true;
  23. }
  24. System.out.println(System.currentTimeMillis() - time);
  25. // for(int i = 0; i<10000; i++) {
  26. // System.out.println(primeList[i]);
  27. // }
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement