티스토리 뷰
public static int[] makePrime(int[] arr) {
for(int i=2; i<arr.length; i++) {
for(int j=2; j<arr.length; j++) {
if(i*j >= arr.length)
break;
if(arr[i*j] == 0)
continue;
arr[i*j] = 0;
}
}
return arr;
}
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
int[] arr = new int[1000];
for(int i=2; i<arr.length; i++) {
arr[i] = i;
}
arr = makePrime(arr);
arr = Arrays.stream(arr).filter(i -> i != 0).toArray();
for(int i=0; i<arr.length; i++) {
System.out.print(arr[i] + " ");
}
}
==========================================================================
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 ...
'Seek > 자료구조&알고리즘' 카테고리의 다른 글
플로이드 와샬 알고리즘 (0) | 2019.10.02 |
---|---|
다익스트라 알고리즘 (0) | 2019.10.02 |
이진 트리 (0) | 2019.10.01 |
크루스칼 알고리즘 (0) | 2019.10.01 |
Union-Find 알고리즘 (0) | 2019.10.01 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- @Service
- 다이나믹 프로그램
- baekjoon
- session-timeout
- @Autowired
- tomcat
- python3
- @RequestParam
- Project facet Java version 10 is not supported
- Project facet Java version
- Persistence
- Server runtime environment
- java
- 내장 객체
- ConnectionPool
- @Controller
- project facet
- Stack
- @ModelAttribute
- java version
- 다이나믹 프로그래밍
- not supported
- @RequestMapping
- angular
- 그리디
- 스택
- SESSION
- @Component
- @Repository
- DP
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
글 보관함