Views 10464 Votes 0 Comment 0
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
소수를 구하는 또다른 방법입니다.

러닝타임은 N + N/2 + N/3 + N/5 + N/7 + N/11 + ....

class Primes {
    public static void main(String[] args) { 
        int num = 100;

        if (args.length > 0)
            num = Integer.parseInt(args[0]);
            
        getPrime(num);
    }

    public static void getPrime(int max) {
        boolean[] a = new boolean[max];
        for (int i = 2; i < max; i++) 
            a[i] = true;
            
        int to = (int)Math.sqrt(max);
        
        for (int i = 2; i < to; i++)
            if (a[i] != false)

        for (int j = i; j*i < max; j++) 
            a[i*j] = false;
                    
        for (int i = 2; i < max; i++)
            if (a[i]) 
                System.out.print(" " + i);

        System.out.println();
    }

}

[출처] http://blog.naver.com/charityno3?Redirect=Log&logNo=80006915007

?

List of Articles
No. Category Subject Author Date Views
505 Develop [c] IP 스푸핑(ip spoof) 소스 - 정리해야 함 file hooni 2003.04.23 8909
504 Database [mysql] CPU 점유율이 높을 때 확인할 내용 hooni 2015.08.26 8899
503 Develop [c] 프로세스 정보 출력하기.. file hooni 2003.04.23 8844
502 Develop [php] 데이터를 엑셀,워드 형태로 변환할 때 헤더(ms-office) hooni 2013.04.23 8842
501 Develop [java] 컴포넌트 배치 ㅡ.,ㅡ; hooni 2003.04.23 8839
500 Develop [c] 정수를 2진수로 변환 (재귀,비트연산) file hooni 2003.04.23 8790
499 Develop [c] 단기과정[01/08] 과제.. 파스칼 삼각형 file hooni 2003.04.23 8772
498 Develop [c] 농구팀 점수 산출 프로그램 소스 file hooni 2003.04.23 8768
497 Develop [js] 이미지 사이즈를 동적으로 조절.. hooni 2013.04.23 8753
496 Develop [c] 프로그램 코드(c/c++)를 html 파일로 변환 file hooni 2013.04.23 8740
495 System/OS HTTPS와 SSL 인증서 file hooni 2014.03.11 8737
494 Develop [c] 코드 최적화에 대해.. hooni 2013.04.23 8710
493 Develop [c#] BFilter 툴바 소스 코드 ㅎㅎ file hooni 2013.04.23 8691
492 Develop [c++] 초간단 스택 두 가지 방식(class, struct) file hooni 2013.04.23 8688
491 Develop 논문 실험용 고려대 툴바 ㅎㅎ secret hooni 2013.04.23 8686
490 Develop [c] 격자 직사각형 넓이 구하기 file hooni 2013.04.23 8686
Board Pagination Prev 1 ... 41 42 43 44 45 ... 74 Next
/ 74