Advertisement
Guest User

Untitled

a guest
Feb 18th, 2015
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.42 KB | None | 0 0
  1.     private static boolean[] getArePrimesArray(int to) {
  2.         boolean[] primes = new boolean[to + 1];
  3.  
  4.         for (int i = 0; i < primes.length; i++) {
  5.             primes[i] = true;
  6.         }
  7.  
  8.         int toSqrt = (int) Math.floor(Math.sqrt(to));
  9.  
  10.         for (int index = 2; index <= toSqrt; index++) {
  11.             if (primes[index] == true) {
  12.                 for (int j = index * index; j <= to; j += index) {
  13.                     primes[j] = false;
  14.                 }
  15.             }
  16.         }
  17.  
  18.         return primes;
  19.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement