2024-10-09 17:02:35 +00:00
|
|
|
export {};
|
|
|
|
|
2024-10-09 17:02:35 +00:00
|
|
|
const isPrime = (number: number) => {
|
|
|
|
for (var i = 2; i < number; i++) {
|
|
|
|
if (number % i === 0) return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
const nthPrime = (n: number) => {
|
|
|
|
const primes: number[] = [];
|
|
|
|
let number = 2;
|
|
|
|
|
|
|
|
while (n > primes.length) {
|
|
|
|
if (isPrime(number)) primes.push(number);
|
|
|
|
number++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return primes[n - 1];
|
|
|
|
};
|
|
|
|
|
|
|
|
console.log(nthPrime(10001));
|