1, the general method, set up the pacesetter, to find
classprime{//Check if it is a prime number Public voidIsPrime () {intm=0; for(intI=1; i<= +; i++){ DoubleCount=0; for(intj =1; j<i;j++){ if(i%j==0) {Count++; } } if(count==1|| i==1) {System. out. print (i +" "); M++; }} System. out. println ("primes are"+m+"a"); } Public Static voidMain (String args[]) {NewPrime (). IsPrime (); }}
2. Screening method
(1), create an array of type Boolean, set the subscript to be an odd value to false, and the subscript of the even number to true
(2), carry out subscript with a value of false, and set the value of the subscript to True
(3), the output value is false subscript
3. Gaussian conjecture '
The number of characters within n is approximately equal to N/LN (n), or, when n is large, the order of magnitude is the same. This is the famous theorem of primes.
Algorithm for finding prime Numbers (0~1000) (Java code)