I have written a program which tests for prime numbers. Please could someone review my code and tell me if there is any way to optimise it as once you start hitting large numbers it takes that much longer to break the loop and return a result.
Code:int prime( long unsigned int &number ) { int factor = 0; for( int i = 1; i <= number; i++ ) if( number % i == 0 )// if there is no remainder - i is a factor of number factor++; if( number == 1 ) return 1; else if( factor == 2 ) // number is prime if only 2 factors are found return 1; else // more than two factors found, number is not prime return 0; } // end function prime