By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.
What is the 10001st prime number?
function isPrime
{
param ($number)
$isPrime = $true
if($number -lt 2) { $isPrime = $False}
if($number -gt 2 -and $number%2 -eq 0) {$isPrime = $False}
for($i=3;$i -le [math]::Sqrt($number);$i+=2)
{
if($number % $i -eq 0) { $isPrime = $False}
}
$isPrime
}
$i = $j = 0
do {
if(isPrime $i){$j++;$i}
$i++
} until ($j -eq 10001)
No comments:
Post a Comment