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 라이브러리에 대한 설명 (static & dynamic library) hooni 2013.04.23 6946
276 Develop [js] 네이버, 다음의 플레이어 스킨 file hooni 2013.04.23 6942
275 Develop [js] php의 number_format() 함수와 같은.. ㅋㅋ hooni 2013.04.23 6938
274 Develop [c] 숫자 맞추는 게임.. file hooni 2013.04.23 6935
273 Develop [c] 도메인(호스트)으로 IP정보 알아오기.. (nslookup과 비슷) file hooni 2013.04.23 6934
272 Develop [c] 단기과정[01/06] sizeof, 실수표현, 메모리, 연산자 hooni 2003.04.23 6928
271 Develop [php] 빔 프로젝터 예약 프로그램.. ㅋㅋ file hooni 2013.04.23 6924
270 Develop [c] 소켓의 세가지 동작모드 hooni 2003.04.23 6913
269 Develop [c] 프로세스 정보 출력하기.. file hooni 2003.04.23 6910
268 Develop [c] 단기과정[01/10] 과제.. swap(any data, ..) file hooni 2003.04.23 6904
267 Develop [c] 맵서치인 듯(옛날 컴에서 찾은 자료) file hooni 2013.04.23 6904
266 Develop [c] pcapdump 파일 분석 하는 프로그램.. ㅋㅋ file hooni 2013.04.23 6902
Board Pagination Prev 1 ... 43 44 45 46 47 48 49 50 51 52 ... 71 Next
/ 71