내 코드
package com.company;
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
int count = 0;
ArrayList<Integer> list = new ArrayList<>();
boolean[] visited = new boolean[N + 1];
for (int i = 2; i <= N; i++) {
int x = 2 * i;
if (!visited[i]) {
list.add(i);
}
while (x <= N) {
visited[x] = true;
x += i;
}
}
int a = 0;
int x = 0;
for (Integer integer : list) {
x += integer;
if (x == N) {
count++;
}
while (x > N) {
x -= list.get(a++);
if (x == N) {
count++;
}
}
}
System.out.println(count);
}
}
'코딩테스트 > [백준] 코딩테스트 연습' 카테고리의 다른 글
빚 - 10427번 (0) | 2022.04.16 |
---|---|
낚시왕 - 17143번 (0) | 2022.04.13 |
캐슬 디펜스 - 17135번 (0) | 2022.04.08 |
큐빙 - 5373번 (0) | 2022.04.08 |
드래곤 커브 - 15685번 (0) | 2022.04.07 |