Contents

조회 수 9339 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
소수를 구하는 또다른 방법입니다.

러닝타임은 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
번호 분류 제목 글쓴이 날짜 조회 수
277 Develop [c] 문자열 정렬 함수 qsort() hooni 2003.04.23 8233
276 Develop [c] 문자열 자르는 함수(strtok) 예제 hooni 2013.04.23 12182
275 Develop [c] 문자열 라이브러리 최신버전 file hooni 2003.04.23 7188
274 Develop [c] 문자열 뒤집기 초간단 샘플 코드 ㅎㅎ hooni 2013.04.23 7121
273 Develop [c] 문자열 뒤집기 (문자열 거꾸로 출력하는 간단소스) hooni 2003.04.23 9984
272 Develop [c] 문자열 str_shift 예제.. file hooni 2013.04.23 6843
271 Develop [c] 무선 Radius Server 자료.. file hooni 2013.04.23 7265
270 Develop [c] 메시지큐(Message Queue) 설명.. (joinc) hooni 2013.04.23 14280
269 Develop [c] 메세지 프로그램 (Server - Agent - Client) file hooni 2013.04.23 6461
268 Develop [c] 맵서치인 듯(옛날 컴에서 찾은 자료) file hooni 2013.04.23 6904
267 Develop [c] 마우스 따라다니는 고양이 - 네코95 (WinAPI) file hooni 2013.04.23 7945
266 Develop [c] 로또(Lotto) 번호 생성기 file hooni 2013.04.23 7175
Board Pagination Prev 1 ... 43 44 45 46 47 48 49 50 51 52 ... 71 Next
/ 71