Hi all , I'm a beginner in C#, I'm trying to write an application to get Primes between two numbers entered by the user .. The Problem is at larg no. like 1 to 10000000 getting the primes takes long time and according to the problem i'm solving, the whole operation must be carried out in a small time interval , this is the problem link for more explanation .. SPOJ-Prime
and here's the part of my code that's responsible of getting primes..
public void GetPrime()
{
int L1 = int.Parse(Limits[0]);
int L2 = int.Parse(Limits[1]);
if (L1 == 1)
{
L1++;
}
for (int i = L1; i <= L2; i++)
{
for (int k = L1; k <= L2; k++)
{
if (i == k)
{
continue;
}
else if (i % k == 0)
{
flag = false;
break;
}
else
{
flag = true;
}
}
if (flag)
{
Console.WriteLine(i);
}
}
}
Is there any faster algorithm ? Thanks in advance .