To verify the conjecture of Goethe Bach

Source: Internet
Author: User

The approximate proof of Goethe Bach's conjecture is that any even number greater than 2 can be expressed as a sum of two primes,
Please write a Java program to verify the correctness of Goethe Bach's conjecture in 1~100.

You write a small program, the code may not be concise, if there are errors, please correct me:

ImportJava.lang.reflect.Array;Importjava.util.ArrayList;Importjava.util.List;/*** Approximate proof of Goethe Bach's conjecture it is said that any even number greater than 2 can be represented as the sum of two primes, * please write a Java program to verify the correctness of Goethe Bach's conjecture in 1~100. * @authorSCYWXX *@version1.0 **/ Public classTest9 { Public Static voidMain (string[] args) {//1 Any even number greater than 2 can be represented as a sum of two primes         for(inti = 4;i<=100;i+=2) {List<Integer> list=method2 (i);                     Method1 (List,i); }                                    }    /*** Statistics The number of all primes of this even number is stored sequentially in a list * prime number is also called prime number. Refers to a natural number greater than 1, except 1 and the integer itself, cannot be divisible by other natural numbers *@paramm represents this integer*/     Public StaticList<integer> Method2 (intm) {List<Integer> list=NewArraylist<integer>();  for(intI =2;i<=m-1;i++)//To determine the number of 2~m-1 in an even number of M        {            //determine if I can be divisible by 2 to i-1            intJ;  for(j=2;j<=i-1;j++)            {                if(i% j = 0)                {                     Break; }            }            //judging the number of cycles equal to I, is prime            if(J = =i) {//Keep the prime number in the listList.add (i); }} System.out.print (M+ "The primes in this even number are:");  for(inti = 0; I < list.size (); i++) {System.out.print (List.get (i)+" ");                        } System.out.println (); returnlist; }    /*** figure out that any even number greater than 2 can be represented as a sum of two primes *@paramThe list represents the collection of all primes that store this even number *@paramm means this even*/     Public Static voidMethod1 (list<integer> List,intm) { for(intJ =1; J<=list.size () -1;j++)//control the distance between the prime number and the prime number each time the distance is calculated        {             for(intn = 0;n<list.size (); n++)            {                //deciding whether to cross the border                if(N+j >=list.size ()) {                     Break; }                //determine if the sum of the primes is equal to the even number.                if(List.get (n) * = =m) {System.out.println (M+ "This even can be expressed as:" +list.get (N) + "and" +list.get (n) + "add"); }                if(List.get (n+j) = =m) {System.out.println (M+ "This even can be expressed as:" +list.get (N) + "and" +list.get (n) + "add"); }                //Add the number of distances separated by the number of pixels equal to this even                if(List.get (n) +list.get (n+j) = =m) {System.out.println (M+ "This even can be expressed as:" +list.get (N) + "and" +list.get (N+J) + "Add"); }                            }        }    }}

Results of the operation:

To verify the conjecture of Goethe Bach

Related Article

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.