哥德巴赫猜想的JAVA实现

package AlgorithmGossip;

/**
*    哥德巴赫猜想大致可以分为两个猜想:
* ■1.每个不小于6的偶数都是两个奇素数之和;
* ■2.每个不小于9的奇数都是三个奇素数之和。
*
* @author yangwen
*
*/
public class Guess{

         public static void main(String args[]){

                 for( int i=6;i<=100;i+=2){
                         for( int j=2;j<100;j++){
                         if(isPrime(j)&&isPrime(i-j)){
                                System.out.println(i+ "="+j+ "+"+(i-j));
                                 break;
                                }
                        }
                }
            
                 for ( int i = 9; i <= 100; i+=2){
                         for ( int j = 2; j < 100; j++){
                                 for( int k = 2; k < (i - j); k++){
                                         if(isPrime(k)&&isPrime(j)&&isPrime(i-k-j)){
                                                System.out.println(i + "=" + j + "+" + k + "+" + (i - j - k));
                                                 break;
                                        }
                                }
                        }
                }
        }
         /**
        * “素数”,又称“质数”,是指:除1和其自身之外,没有其它约数的正整数
        * 如 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,...
        * 2是最小的质数,也是唯一的偶质数,质数有无数多个
        * 与素数相对的,有“合数”:
        * 除1和其自身之外,仍有其它约数的正整数 规定:1既不是质数,也不是合数
        * @param n
        * @return
        */
         public static boolean isPrime( int n){
                         for( int i=2;i<n;i++)
                        {
                                 if(n%i==0){
                                         return false;
                                }
                        }
                         return true;
                }
        }

你可能感兴趣的:(职场,java算法,休闲,哥德巴赫猜想)