Contents

조회 수 10464 댓글 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
번호 분류 제목 글쓴이 날짜 조회 수
541 Develop [c] GD라이브러리 설치 테스트 소스 file hooni 2013.04.23 9238
540 Develop [java] RGB코드를 HEX코드로 변환하는 코드 ㅎㅎ hooni 2013.04.23 9230
539 Develop [js] 셀렉트박스(select)의 옵션(option) 동적으로 추가/제거 file hooni 2013.04.23 9228
538 Develop [c] 구구단 최단라인 ㅡㅡ; file hooni 2013.04.23 9226
537 Develop [js] 핫키(단축키) 구현방법 hooni 2003.04.23 9224
536 Develop [c] 퀵정렬(quick sort) 예제 소스.. file hooni 2013.04.23 9223
535 Develop [c] 포인터와 함수포인터에 대해.. hooni 2003.04.23 9212
534 Develop [c++] Win32API를 이용한 ExitWindowsEx 사용한 예제코드 hooni 2013.04.23 9206
533 Develop [c] 단기과정[01/08] (다차원 + 배열)포인터, void 포인터 hooni 2003.04.23 9205
532 Develop [vb] 64bit RSA 프로그램 소스 ㅋㅋ file hooni 2013.04.23 9200
531 Develop [c] 문자열 처리 관련 함수들 설명 hooni 2003.04.23 9186
530 Develop [js] 자바스크립트 이벤트 핸들.. hooni 2003.04.23 9160
Board Pagination Prev 1 ... 49 50 51 52 53 54 55 56 57 58 ... 99 Next
/ 99