Algorithm for finding prime Numbers (0~1000) (Java code)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.