Contents

조회 수 10466 댓글 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
번호 분류 제목 글쓴이 날짜 조회 수
805 System/OS [sql] 내 방명록 답글 찾는 쿼리문.. (JOIN 구문) hooni 2003.04.23 13777
804 System/OS [linux] DHCP(Dynamic Host Configuration Protocol) 서버 hooni 2003.04.23 13742
803 PPT [doc] 위탁과제 제안서와 발표자료(pdf) file hooni 2013.04.23 13713
802 Develop [iphone] 아이폰 어플 모음 ㅋㅋ secret hooni 2013.04.23 13707
801 Database [oracle] SQL문 실행 방법 3가지 file hooni 2013.12.19 13694
800 System/OS [router] 시스코 라우터 명령어 모드.. hooni 2013.04.23 13676
799 Develop [js] 자바스크립트의 클로저 (JavaScript's Closure) hooni 2013.05.15 13672
798 System/OS [linux] root 전환시 패스워드 없이 su 사용하기 hooni 2013.12.22 13639
797 Develop [php] 하루 전 날짜 쉽게 구하기. hooni 2013.12.25 13596
796 Etc [flash] 맘에 드는 파이차트 file hooni 2013.04.23 13589
795 Develop [ios] UIButton multi-line iOS7 hooni 2014.01.09 13586
794 Develop [ios] GCD 변수 사용 예제 hooni 2013.10.01 13580
Board Pagination Prev 1 ... 27 28 29 30 31 32 33 34 35 36 ... 99 Next
/ 99