Views 9337 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
293 Develop [css] z-index에 설정할 수 있는 최대값? hooni 2013.12.20 14705
292 Etc [htm] DOM에 대해 ㅎㅎ file hooni 2003.04.23 14717
291 System/OS [linux] 랜카드 2개 설정 & iptables 로 사설 ip.. hooni 2003.04.23 14732
290 System/OS [sql] 중복데이터 삭제 쿼리 hooni 2013.04.23 14734
289 Develop [unix] 날짜 관련 쉘 명령어 (특정일 또는 +-시간, 날짜 계산된 값) hooni 2013.04.23 14803
288 Develop [ios] UIWebView에서 NSURLRequest에 Cookie 실어 보내기 hooni 2014.01.16 14859
287 System/OS [linux] 웹로그분석기(webalizer) 설치 & 팁 hooni 2003.04.23 14882
286 System/OS [linux] 이기종간의 파일 공유(Samba) hooni 2003.04.23 14900
285 Develop [unix] 쉘 스크립트 예제 모음 hooni 2003.04.23 14949
284 Develop [c++][mfc] 파일 입출력 샘플 (한줄씩 읽어서 다른 파일에 쓰기) hooni 2013.04.23 14981
283 System/OS [perl] 펄 환경 설정해야 할거 ㅋㅋ hooni 2003.04.23 14992
282 System/OS [linux] 아파치설치/설정 - 사용인증 hooni 2003.04.23 15084
281 Database [sql] 간단한 통계 서브쿼리 예제.. hooni 2013.04.23 15088
280 Develop [c] GD라이브러리(jpeg)를 사용한 웹 카운터 샘플 hooni 2013.04.23 15107
279 Algorithm [algorithm] Greedy (탐욕 기법) hooni 2003.04.23 15108
278 Etc 여러 대학 및 권위있는 기관 강좌 모음 ㅋㅋ hooni 2013.06.17 15119
Board Pagination Prev 1 ... 54 55 56 57 58 ... 74 Next
/ 74