The third homework of st

package 作业3;

public class printPrimes {
    public static void main(String[] args){
        int n=3;
        printPrimes(n);
    }
private static void printPrimes(int n){
    int curPrime;
    int numPrimes;
    boolean isPrime;
    int MAXPRIMES=100;
    int[] primes = new int [MAXPRIMES];
    
    primes[0]=2;
    numPrimes=1;
    curPrime=2;
    while(numPrimes<n){
        curPrime++;
        isPrime=true;
        for(int i=0;i<=numPrimes-1;i++){
            if((curPrime % primes[i]) == 0){
                isPrime=false;
                break;
            }
        }
        if(isPrime){
            primes[numPrimes]=curPrime;
            numPrimes++;
        }
        
    }
    for(int i=0;i<=numPrimes-1;i++){
        System.out.println("Primes: "+primes[i]);
    }
}
}

(a)

 

(b)Assume that MAXPRIMES=4, and t2 is easier to find due to out of bounds;

(c)n=1

(d)

NC={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};

EC: {(1,2), (2,3), (3,4), (4,5), (5,6), (6,7), (7,5), (6,8), (5,9), (8,9), (9,2), (9,10), (10,2), (2,11), (11,12), (12,13), (13,14), (14,12), (12,15)};

PPC: { (1,2,3,4,5,6,7), (1,2,3,4,5,6,8,9,10),(1,2,3,4,5,9,10), (1,2,11,12,15),(1,2,11,12,13,14), (2,3,4,5,6,8,9,2),(3,4,5,6,8,9,2,3), (4,5,6,8,9,2,3,4),(5,6,8,9,2,3,4,5), (6,8,9,2,3,4,5,6),(8,9,2,3,4,5,6,8), (9,2,3,4,5,6,8,9),(2,3,4,5,6,8,9,10,2), (3,4,5,6,8,9,10,2,3),(4,5,6,8,9,10,2,3,4), (5,6,8,9,10,2,3,4,5),(6,8,9,10,2,3,4,5,6), (8,9,10,2,3,4,5,6,8),(9,10,2,3,4,5,6,8,9), (10,2,3,4,5,6,8,9,10),(2,3,4,5,9,2), (3,4,5,9,2,3),(4,5,9,2,3,4), (5,9,2,3,4,5),(9,2,3,4,5,9), (2,3,4,5,9,10,2),(3,4,5,9,10,2,3), (4,5,9,10,2,3,4),(5,9,10,2,3,4,5), (9,10,2,3,4,5,9),(10,2,3,4,5,9,10), (3,4,5,6,8,9,2,11,12,15),(3,4,5,6,8,9,2,11,12,13,14), (3,4,5,6,8,9,10,2,11,12,15),(3,4,5,6,8,9,10,2,11,12,13,14), (3,4,5,9,2,11,12,15),(3,4,5,9,2,11,12,13,14), (3,4,5,9,10,2,11,12,13,14),(3,4,5,9,10,2,11,12,15), (5,6,7,5),(6,7,5,6), (7,5,6,7),(6,7,5,9,2,11,12,13,14), (6,7,5,9,2,11,12,15),(6,7,5,9,10,2,11,12,13,14), (6,7,5,9,10,2,11,12,15),(6,7,5,9,2,3,4), (6,7,5,9,10,2,3,4),(7,5,6,8,9,2,3,4), (7,5,6,8,9,10,2,3,4),(12,13,14,12), (13,14,12,13),(14,12,13,14), (13,14,12,15)};

 

posted @ 2017-03-14 21:34  ForThree  阅读(126)  评论(0编辑  收藏  举报