title: Efficient algorithm to get primes between two large numbers
body: <p>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 large numbers (valid numbers are in the range from 1 to 1000000000) 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:
  <a href="https://www.spoj.pl/problems/PRIME1/" rel="nofollow noreferrer">SPOJ-Prime</a></p>
  
  <p>And here's the part of my code that's responsible of getting primes:</p>
  
  <pre><code>  public void GetPrime()
      {            
          int L1 = int.Parse(Limits[0]);
          int L2 = int.Parse(Limits[1]);
  
          if (L1 == 1)
          {
              L1++;
          }
  
          for (int i = L1; i &lt;= L2; i++)
          {
              for (int k = L1; k &lt;= L2; k++)
              {
                  if (i == k)
                  {
                      continue;
                  }
                  else if (i % k == 0)
                  {
                      flag = false;
                      break;
                  }
                  else
                  {
                      flag = true;
                  }
              }
  
              if (flag)
              {
                  Console.WriteLine(i);
              }
          }
      }
  </code></pre>
  
  <p>Is there any faster algorithm? 
  Thanks in advance.</p>