Source/NFX/IntMath.cs
/// <summary>
/// Tests if the number is prime
/// </summary>
Tests if the number is prime
Tests if the number is prime
public static bool IsPrime(int number)
        {
          if (number<2) return false;
          if ((number & 1)==0)
           return number==2;
          for(var i=3; (i*i) <= number; i+=2)
           if ((number % i) == 0) return false;
          return number!=1;
        }
public static bool IsPrime ( int number ) { if ( number < 2 ) return false ; if ( ( number & 1 ) == 0 ) return number == 2 ; for ( var i = 3 ; ( i * i ) <= number ; i += 2 ) if ( ( number % i ) == 0 ) return false ; return number != 1 ; }
Tests if the number is prime
Tests if the number is prime
//1 parity case //divisible by 2 //only 2 is prime, other numbers divisible by 2 are not //check odd numbers starting from 3 (+2 to check only odd numbers, as even are already covered)
number
int