1
私は7番目のプロジェクトオイラーの問題を抱えています。なぜこのコードがうまくいかないのかよく分かりません。それは問題ありませんが、10001で正解を返しません - 返す104745。10001st Prime - Project Euler
はい、私はそれが非効率的であることを知っています。
private void eulerSeven(int num)
{
// Start the Prime count at 3, with 2 already counted.
int primecount = 1, counter = 3;
//While num of primes counted < the nth prime
while (primecount < num)
{
bool isPrime = true;
//check every number from 2 -> the current number we're checking
for (int i = 2; i < counter; i++)
{
if (counter%i == 0)
{
//if divisible, not a prime
isPrime = false;
break;
}
}
if (isPrime) //If is a prime, increment counter
{ primecount++; }
// Go to next number (only checking odds)
counter += 2;
}
//output nth prime
Console.WriteLine(counter);
}
コードを表示'//出力n番目のプライム 'の場合 – Lanorkin
Console.WriteLine(counter); –
は 'counter-2'にする必要があります。 – Lanorkin