title: Fastest way to calculate Prime
body: <p>I'm trying to Implement types of primes in my program. In one of the type Exponent Of Mersenne, the formula to calculate is <code>(2 power P) -1</code> Here <code>P is Prime.</code> and check the output is prime.</p>
  
  <p>In calculating, I'm able to get the power but while checking for prime, the process is Hanging . and if I leave it for a very long long time then it is being calculated.</p>
  
  <p>example would be, (2 power 10090) -1 and calculate if this is prime</p>
  
  <p>I'm using Big Integer</p>
  
  <p>I'musing this code</p>
  
  <pre><code>int prime1 = CalculatePrime(n);
  BigInteger powerPrime = BigInteger.Pow(2, prime1);
  bool isPrime = CheckPrime(powerPrime - 1);
  
  private bool CheckPrime(BigInteger num)
  {
      if (num == 0 || num == 1) 
          return false;
  
      bool isPrime = true;
      for (int j = 2; j &lt; num; j++)
      {
          if ((num % j) == 0)
          {
              isPrime = false;
              break;
          }
      }
      return isPrime;
  }
  </code></pre>
  
  <p>How would be this - <a href="http://www.dotnetperls.com/prime" rel="nofollow">http://www.dotnetperls.com/prime</a></p>