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


?

  1. [java] 거스름돈 계산.. swing 사용

  2. [c] 하노이탑 - 재귀함수

  3. [doc] 유료 방송 제어 시스템 (CAS) 발표자료

  4. [c] 오목.. 간단한 소스 ㅋㅋ

  5. [c] SetTimer() & KillTimer() & 일회용 Timer

  6. [c][java] 그래픽(graphic)관련 자료와 샘플코드..

  7. [c++] 링크리스트(linked list) 클래스(스택,큐)

  8. [js] One Time Pad key generatorㅡ.,ㅡ;

  9. [ios] 한샘 카달로그 앱 소스 (아이폰용)

  10. [c] 팩토리얼.. - 재귀함수

  11. [php] 자주 쓰는 PHP 함수와 예제

  12. [chm] Programming Applications for Microsoft Windows

Board Pagination Prev 1 ... 41 42 43 44 45 46 47 48 49 50 ... 71 Next
/ 71