Develop
2013.04.23 14:07
[java] Sieve of Eratosthenes (에라토스테네스의 체)
조회 수 9347 댓글 0
소수를 구하는 또다른 방법입니다.
러닝타임은 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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
681 | System/OS | [linux] 프로세스의 stat 상태에 대한 설명 | hooni | 2013.04.23 | 10823 |
680 | Develop |
[php] 빔 프로젝터 예약 프로그램.. ㅋㅋ
![]() |
hooni | 2013.04.23 | 6947 |
679 | Develop |
[php] 논문 관리 프로그램.. ㅋㅋ
![]() |
hooni | 2013.04.23 | 7274 |
678 | Develop |
[c++] 프리렉(freelec) 예제 자료.. ㅋㄷ
![]() |
hooni | 2013.04.23 | 6848 |
677 | Develop |
[c++] 템플릿(Template) 예제 소스..
![]() |
hooni | 2013.04.23 | 6995 |
676 | Develop | [php] 현재에서 일정한 날짜 더하기.. | hooni | 2013.04.23 | 7150 |
675 | Develop | [c++] 문자열 뒤집기(문자열 거꾸로 출력) | hooni | 2013.04.23 | 17305 |
674 | Develop | [C++] 18일차 과제물, String 클래스 디자인 【 C++ 문제 】 | hooni | 2013.04.23 | 7055 |
673 | Develop | [php] 이미지 회전시키기(gd) | hooni | 2013.04.23 | 7345 |
672 | Develop | [js] 서서히 나타나는 화면.. ㅋㅋ | hooni | 2013.04.23 | 6218 |
671 | PPT |
[doc] 논문.. VoIP 관련.. ㅋㅋ
![]() |
hooni | 2013.04.23 | 17103 |
670 | System/OS | [linux] ssh에서 원격 파일 전송하기.. | hooni | 2013.04.23 | 14205 |