Develop
2013.04.23 14:07
[java] Sieve of Eratosthenes (에라토스테네스의 체)
조회 수 9348 댓글 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
-
[c] 다중연결 서버 만들기 #2 - select() 사용
-
[php] Laravel 5.4: Specified key was too long error
-
[c++] 더블 링크리스트(linked list) 학습용 초간단 단어장
-
[c++] MFC로 만든 디렉토리/파일 파인더
-
[java] Sieve of Eratosthenes (에라토스테네스의 체)
-
[js] 폼(form) 전송시 중복 클릭 방지 간단한 구문
-
[c] 전위 표기법으로 연산 예제..
-
[c] 도메인 소켓(Unix Domain Socket) UDP
-
[ios] In App Purchase 개발
-
[c++] mfc이용한 트레이아이콘(TrayIcon) 클래스 예제 프로젝트
-
[c++] RSA Sample 4 CPP
-
[c] SetTimer() & KillTimer() & 일회용 Timer