Contents

Views 10464 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
685 System/OS [linux] 프로세스의 stat 상태에 대한 설명 hooni 2013.04.23 11887
684 Develop [php] 빔 프로젝터 예약 프로그램.. ㅋㅋ file hooni 2013.04.23 7974
683 Develop [php] 논문 관리 프로그램.. ㅋㅋ file hooni 2013.04.23 7972
682 Develop [c++] 프리렉(freelec) 예제 자료.. ㅋㄷ file hooni 2013.04.23 7830
681 Develop [c++] 템플릿(Template) 예제 소스.. file hooni 2013.04.23 7968
680 Develop [php] 현재에서 일정한 날짜 더하기.. hooni 2013.04.23 8451
679 Develop [c++] 문자열 뒤집기(문자열 거꾸로 출력) hooni 2013.04.23 18079
678 Develop [C++] 18일차 과제물, String 클래스 디자인 【 C++ 문제 】 hooni 2013.04.23 8161
677 Develop [php] 이미지 회전시키기(gd) hooni 2013.04.23 8216
676 Develop [js] 서서히 나타나는 화면.. ㅋㅋ hooni 2013.04.23 7181
675 PPT [doc] 논문.. VoIP 관련.. ㅋㅋ file hooni 2013.04.23 18042
674 System/OS [linux] ssh에서 원격 파일 전송하기.. hooni 2013.04.23 15044
Board Pagination Prev 1 ... 37 38 39 40 41 42 43 44 45 46 ... 99 Next
/ 99