Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- 시뮬레이션
- Java
- math
- COS PRO
- 백준
- oracle
- MySQL
- db
- BFS
- 문제풀이
- 문제해결
- binary search
- SWEA
- 코딩테스트
- 운동기록
- priorityqueue
- 투포인터
- 알고리즘
- 자바
- 프로그래머스
- greedy
- BOJ
- dfs
- 이분탐색
- 건강
- 문자열
- DP
- 코테
- 러닝일지
- SQL
Archives
- Today
- Total
슈콩
[BOJ] 백준 3343 장미 본문
범위 주의 !
[문제]
https://www.acmicpc.net/problem/4948
[소스 코드]
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while(true) {
int n = Integer.parseInt(br.readLine());
if(n==0) break;
if(n==1) {
System.out.println(1);
continue;
}
int result = 0;
boolean[] prime = new boolean[2*n+1];
Arrays.fill(prime,true);
for(int i=2;i*i<=2*n;i++) {
if(!prime[i])
continue;
for(int j=i*i;j<=2*n;j+=i) {
prime[j] = false;
}
}
for(int i=n+1;i<=2*n;i++) {
if(prime[i])
result++;
}
System.out.println(result);
}
}
}'Algorithms > Baekjoon' 카테고리의 다른 글
| [BOJ] 백준 6359 만취한 상범 (0) | 2025.09.15 |
|---|---|
| [BOJ] 백준 5347 LCM (0) | 2025.09.15 |
| [BOJ] 백준 3343 캠핑 (0) | 2025.09.15 |
| [BOJ] 백준 3343 장미 (0) | 2025.09.15 |
| [BOJ] 백준 3036 링 (0) | 2025.09.15 |