@Test(expected=IllegalArgumentException.class) public void testListPrimalityInvalid0() { Library.listPrimality(-1); }
public static boolean[] listPrimality(int n) { if (n < 0) throw new IllegalArgumentException("Negative array size"); boolean[] result = new boolean[n + 1]; if (n >= 2) result[2] = true; for (int i = 3; i <= n; i += 2) result[i] = true; for (int i = 3, end = sqrt(n); i <= end; i += 2) { if (result[i]) { for (int j = i * i, inc = i * 2; j <= n; j += inc) result[j] = false; } } return result; }
Library { public static boolean[] listPrimality(int n) { if (n < 0) throw new IllegalArgumentException("Negative array size"); boolean[] result = new boolean[n + 1]; if (n >= 2) result[2] = true; for (int i = 3; i <= n; i += 2) result[i] = true; for (int i = 3, end = sqrt(n); i <= end; i += 2) { if (result[i]) { for (int j = i * i, inc = i * 2; j <= n; j += inc) result[j] = false; } } return result; } }
Library { public static boolean[] listPrimality(int n) { if (n < 0) throw new IllegalArgumentException("Negative array size"); boolean[] result = new boolean[n + 1]; if (n >= 2) result[2] = true; for (int i = 3; i <= n; i += 2) result[i] = true; for (int i = 3, end = sqrt(n); i <= end; i += 2) { if (result[i]) { for (int j = i * i, inc = i * 2; j <= n; j += inc) result[j] = false; } } return result; }  }
Library { public static boolean[] listPrimality(int n) { if (n < 0) throw new IllegalArgumentException("Negative array size"); boolean[] result = new boolean[n + 1]; if (n >= 2) result[2] = true; for (int i = 3; i <= n; i += 2) result[i] = true; for (int i = 3, end = sqrt(n); i <= end; i += 2) { if (result[i]) { for (int j = i * i, inc = i * 2; j <= n; j += inc) result[j] = false; } } return result; }  static String reverse(String s); static boolean isPalindrome(String s); static boolean isPalindrome(int x); static int sqrt(int x); static long sqrt(long x); static BigInteger sqrt(BigInteger x); static boolean isSquare(int x); static int pow(int x, int y); static int powMod(int x, int y, int m); static int reciprocalMod(int x, int m); static BigInteger factorial(int n); static BigInteger binomial(int n, int k); static int gcd(int x, int y); static boolean isPrime(int x); static boolean[] listPrimality(int n); static int[] listPrimes(int n); static int[] listSmallestPrimeFactors(int n); static int totient(int n); static int[] listTotients(int n); static boolean nextPermutation(int[] arr); }
Library { public static boolean[] listPrimality(int n) { if (n < 0) throw new IllegalArgumentException("Negative array size"); boolean[] result = new boolean[n + 1]; if (n >= 2) result[2] = true; for (int i = 3; i <= n; i += 2) result[i] = true; for (int i = 3, end = sqrt(n); i <= end; i += 2) { if (result[i]) { for (int j = i * i, inc = i * 2; j <= n; j += inc) result[j] = false; } } return result; }  static String reverse(String s); static boolean isPalindrome(String s); static boolean isPalindrome(int x); static int sqrt(int x); static long sqrt(long x); static BigInteger sqrt(BigInteger x); static boolean isSquare(int x); static int pow(int x, int y); static int powMod(int x, int y, int m); static int reciprocalMod(int x, int m); static BigInteger factorial(int n); static BigInteger binomial(int n, int k); static int gcd(int x, int y); static boolean isPrime(int x); static boolean[] listPrimality(int n); static int[] listPrimes(int n); static int[] listSmallestPrimeFactors(int n); static int totient(int n); static int[] listTotients(int n); static boolean nextPermutation(int[] arr);  }