Sha256: 93324f8bb569bd85737574c92e4ab75a20f7da39e9d4c70fd0152dee219d0ec9
Contents?: true
Size: 850 Bytes
Versions: 141
Compression:
Stored size: 850 Bytes
Contents
import java.util.stream.IntStream; public final class Prime { public static int nth(int nth) { if (nth < 1) { throw new IllegalArgumentException(); } int primesFound = 0; int possiblePrime = 1; while (primesFound < nth) { possiblePrime++; if (isPrime(possiblePrime)) { primesFound++; } } return possiblePrime; } private static boolean isPrime(int n) { if (n == 1) { return false; } if (n == 2) { return true; } boolean divisible = IntStream .rangeClosed(2, (int) Math.ceil(Math.sqrt(n))) .anyMatch((int i) -> n % i == 0); if (divisible) { return false; } return true; } }
Version data entries
141 entries across 141 versions & 1 rubygems