Contents

조회 수 9346 댓글 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


?

  1. [english] 영어공부 혼자 하기, 인터넷으로 영어공부하기 추천사이트 20선

  2. [java] 스윙(swing)버튼 테스트 ㅋㅋ

  3. [js] jQuery 셀랙터(selector) 요약

  4. [c] 공용체를 이용해 MSB를 LSB로 변환

  5. [c] 다중연결 서버 만들기 #2 - select() 사용

  6. [c++] 더블 링크리스트(linked list) 학습용 초간단 단어장

  7. [php] Laravel 5.4: Specified key was too long error

  8. [c++] MFC로 만든 디렉토리/파일 파인더

  9. [java] Sieve of Eratosthenes (에라토스테네스의 체)

  10. [js] 폼(form) 전송시 중복 클릭 방지 간단한 구문

  11. [c] 전위 표기법으로 연산 예제..

  12. [c] 도메인 소켓(Unix Domain Socket) UDP

Board Pagination Prev 1 ... 38 39 40 41 42 43 44 45 46 47 ... 98 Next
/ 98