Contents

조회 수 9335 댓글 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
번호 분류 제목 글쓴이 날짜 조회 수
417 Develop [c] 학생명단 관리 프로그램 소스 ㅋㅋ 1 file hooni 2003.04.23 7751
416 Develop [c] 학교 건물 최단거리 찾는 웹 연동 프로그램 file hooni 2013.04.23 6800
415 Develop [c] 하노이탑 - 재귀함수 hooni 2003.04.23 9153
414 Develop [c] 플러드 필링 (flood filling) 알고리즘.. file hooni 2013.04.23 7318
413 Develop [c] 프로세스간의 통신(파이프) hooni 2003.04.23 6891
412 Develop [c] 프로세스 정보 출력하기.. file hooni 2003.04.23 6904
411 Develop [c] 프로세스 검사하기 hooni 2013.04.23 8027
410 Develop [c] 프로그램 코드(c/c++)를 html 파일로 변환 file hooni 2013.04.23 7675
409 Develop [c] 프로그래밍의 전반적인 설명 ppt file hooni 2003.04.23 7659
408 Develop [c] 프로그래밍 과제..(colprint) file hooni 2003.04.23 6745
407 Develop [c] 프로그래밍 ppt, 스킬업 (비트 수업자료) file hooni 2003.04.23 8177
406 Develop [c] 포인터와 함수포인터에 대해.. hooni 2003.04.23 8019
Board Pagination Prev 1 ... 59 60 61 62 63 64 65 66 67 68 ... 98 Next
/ 98