public static void main(String[] argv) { Primes primes = Primes.Instance; int[] testInput = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}; int[] testOutput = {-1, -1, 2, 3, 3, 5, 5, 7, 7, 7, 7, 11, 11, 13, 13, 13, 13, 17, 17, 19, 19}; int testIn, testOut, result, errors = 0; for (int cc = 0, count = testInput.length; cc < count; cc++) { testIn = testInput[cc]; testOut = testOutput[cc]; result = primes.floor(testIn); if (result == testOut) System.out.println(String.format("OK primes.floor(%d) => (prime %d)", testIn, result)); else { errors += 1; System.out.println( String.format( "ER primes.floor(%d) => (prime %d) != (expected %d)", testIn, result, testOut)); } } if (0 < errors) { System.out.println(String.format("Error: count %d", errors)); System.exit(1); } else { System.out.println("OK Primes passed with no errors"); System.exit(0); } }
public void run() { BigInteger start = Primes.random(numDigits); for (int i = 0; i < numPrimes; i++) { start = Primes.nextPrime(start); synchronized (this) { primesFound.add(start); } } }
public static final int Floor(int num) { return Instance.ceil(num); }
public static final int Get(int idx) { return Instance.get(idx); }