Develop
2013.04.23 14:07
[java] Sieve of Eratosthenes (에라토스테네스의 체)
조회 수 10464 댓글 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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
397 | Develop | [linux] CentOS Apache 웹서버에 HTTPS 적용 | hooni | 2015.10.23 | 2089 |
396 | System/OS | [linux] CentOS 에 APM 설치하기 | hooni | 2015.01.02 | 2981 |
395 | System/OS | [linux] CentOS 터미널 언어 설정(한글/영어) | hooni | 2013.12.22 | 19557 |
394 | Develop | [linux] crond 사용법.. ㅋㅋ | hooni | 2013.04.23 | 8271 |
393 | System/OS | [linux] DHCP(Dynamic Host Configuration Protocol) 서버 | hooni | 2003.04.23 | 13739 |
392 | System/OS | [linux] DNS(Domain Name System) 설치, 설정 | hooni | 2003.04.23 | 13239 |
391 | System/OS |
[linux] GD 라이브러리 설치 방법..
![]() |
hooni | 2013.04.23 | 12361 |
390 | System/OS |
[linux] iconv를 이용하여 euc-kr 문서를 utf-8로 대량으로 변환하기
![]() |
hooni | 2014.01.09 | 13430 |
389 | System/OS | [linux] ipchains 사용예(패킷 필터링) | hooni | 2003.04.23 | 15017 |
388 | System/OS | [linux] ipchains 옵션 | hooni | 2003.04.23 | 14447 |
387 | System/OS | [linux] ipfwadm를 이용한 패킷필터링(구버전) | hooni | 2003.04.23 | 13950 |
386 | System/OS | [linux] iptables 명령어 매뉴얼(options) | hooni | 2003.04.23 | 12623 |