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