I want to print the first 10000 prime numbers. Can anyone give me the most efficient code for this? Clarifications:
Adapting and following on from GateKiller, here's the final version that I've used.
public IEnumerable PrimeNumbers(long number)
{
List primes = new List();
for (int i = 2; primes.Count < number; i++)
{
bool divisible = false;
foreach (int num in primes)
{
if (i % num == 0)
divisible = true;
if (num > Math.Sqrt(i))
break;
}
if (divisible == false)
primes.Add(i);
}
return primes;
}
It's basically the same, but I've added the "break on Sqrt" suggestion and changed some of the variables around to make it fit better for me. (I was working on Euler and needed the 10001th prime)