Idea: 1. (prime number filtering theorem) n cannot be divisible by any prime number not greater than root number N, then n is a prime number.
2. Even numbers except 2 are not prime numbers.
The Code is as follows:
/*** Calculate the prime number in N * @ Param int $ N * @ return array */function get_prime ($ n) {$ prime = array (2 ); // 2 is the prime number for ($ I = 3; $ I <= $ N; $ I + = 2) {// the even number is not the prime number, increase the step size by $ SQRT = intval (SQRT ($ I); // obtain the root number N for ($ J = 3; $ j <= $ SQRT; $ J + = 2) {// I is an odd number. Of course, it cannot be divisible by an even number. The step size can also be increased. If ($ I % $ J = 0) {break;} if ($ j> $ SQRT) {array_push ($ Prime, $ I );}} return $ prime;} print_r (getprime (1000 ));
Evaluate the prime number within N (definition of prime number: in a natural number greater than 1, apart from 1 and itself, it cannot be divisible by other natural numbers)