@Test public void testPrimeNumber() { final int[] primes = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113 }; for (int i=0; i<primes.length; i++) { assertEquals(primes[i], primeNumber(i)); } }
public static synchronized int primeNumber(final int index) throws IndexOutOfBoundsException { if (index < 0 || index >= MAX_PRIMES_LENGTH) { throw new IndexOutOfBoundsException(String.valueOf(index)); } short[] primes = XMath.primes; if (index >= primes.length) { int i = primes.length; int n = primes[i - 1] & 0xFFFF; primes = XArray.resize(primes, Math.min((index | 0xF) + 1, MAX_PRIMES_LENGTH)); do { next: while (true) { n += 2; for (int j=1; j<i; j++) { if (n % (primes[j] & 0xFFFF) == 0) { continue next; } } assert n < 0xFFFF : i; primes[i] = (short) n; break; } } while (++i < primes.length); XMath.primes = primes; } return primes[index] & 0xFFFF; }
XMath { public static synchronized int primeNumber(final int index) throws IndexOutOfBoundsException { if (index < 0 || index >= MAX_PRIMES_LENGTH) { throw new IndexOutOfBoundsException(String.valueOf(index)); } short[] primes = XMath.primes; if (index >= primes.length) { int i = primes.length; int n = primes[i - 1] & 0xFFFF; primes = XArray.resize(primes, Math.min((index | 0xF) + 1, MAX_PRIMES_LENGTH)); do { next: while (true) { n += 2; for (int j=1; j<i; j++) { if (n % (primes[j] & 0xFFFF) == 0) { continue next; } } assert n < 0xFFFF : i; primes[i] = (short) n; break; } } while (++i < primes.length); XMath.primes = primes; } return primes[index] & 0xFFFF; } }
XMath { public static synchronized int primeNumber(final int index) throws IndexOutOfBoundsException { if (index < 0 || index >= MAX_PRIMES_LENGTH) { throw new IndexOutOfBoundsException(String.valueOf(index)); } short[] primes = XMath.primes; if (index >= primes.length) { int i = primes.length; int n = primes[i - 1] & 0xFFFF; primes = XArray.resize(primes, Math.min((index | 0xF) + 1, MAX_PRIMES_LENGTH)); do { next: while (true) { n += 2; for (int j=1; j<i; j++) { if (n % (primes[j] & 0xFFFF) == 0) { continue next; } } assert n < 0xFFFF : i; primes[i] = (short) n; break; } } while (++i < primes.length); XMath.primes = primes; } return primes[index] & 0xFFFF; } private  XMath(); }
XMath { public static synchronized int primeNumber(final int index) throws IndexOutOfBoundsException { if (index < 0 || index >= MAX_PRIMES_LENGTH) { throw new IndexOutOfBoundsException(String.valueOf(index)); } short[] primes = XMath.primes; if (index >= primes.length) { int i = primes.length; int n = primes[i - 1] & 0xFFFF; primes = XArray.resize(primes, Math.min((index | 0xF) + 1, MAX_PRIMES_LENGTH)); do { next: while (true) { n += 2; for (int j=1; j<i; j++) { if (n % (primes[j] & 0xFFFF) == 0) { continue next; } } assert n < 0xFFFF : i; primes[i] = (short) n; break; } } while (++i < primes.length); XMath.primes = primes; } return primes[index] & 0xFFFF; } private  XMath(); static double pow10(final double x); static strictfp double pow10(final int x); static int sgn(final double x); static int sgn(final float x); static int sgn(long x); static int sgn(int x); static short sgn(short x); static byte sgn(byte x); static double roundIfAlmostInteger(final double value, int maxULP); static double trimDecimalFractionDigits(final double value, final int maxULP, int n); static int countDecimalFractionDigits(final double value); static float toNaN(int index); static synchronized int primeNumber(final int index); static int[] divisors(int number); }
XMath { public static synchronized int primeNumber(final int index) throws IndexOutOfBoundsException { if (index < 0 || index >= MAX_PRIMES_LENGTH) { throw new IndexOutOfBoundsException(String.valueOf(index)); } short[] primes = XMath.primes; if (index >= primes.length) { int i = primes.length; int n = primes[i - 1] & 0xFFFF; primes = XArray.resize(primes, Math.min((index | 0xF) + 1, MAX_PRIMES_LENGTH)); do { next: while (true) { n += 2; for (int j=1; j<i; j++) { if (n % (primes[j] & 0xFFFF) == 0) { continue next; } } assert n < 0xFFFF : i; primes[i] = (short) n; break; } } while (++i < primes.length); XMath.primes = primes; } return primes[index] & 0xFFFF; } private  XMath(); static double pow10(final double x); static strictfp double pow10(final int x); static int sgn(final double x); static int sgn(final float x); static int sgn(long x); static int sgn(int x); static short sgn(short x); static byte sgn(byte x); static double roundIfAlmostInteger(final double value, int maxULP); static double trimDecimalFractionDigits(final double value, final int maxULP, int n); static int countDecimalFractionDigits(final double value); static float toNaN(int index); static synchronized int primeNumber(final int index); static int[] divisors(int number);  }