Skip to content

Commit f69c8e5

Browse files
authored
[20250702] BOJ / G3 / 소수의 연속합 / 이강현
1 parent 2908017 commit f69c8e5

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
```java
2+
import java.util.*;
3+
import java.io.*;
4+
5+
public class Main{
6+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
8+
static StringTokenizer st;
9+
static int N;
10+
static List<Integer> primes = new ArrayList<>();
11+
12+
public static void main(String[] args) throws Exception{
13+
N = Integer.parseInt(br.readLine());
14+
if(N == 1){
15+
bw.write("0");
16+
bw.close();
17+
return;
18+
}
19+
20+
loop: for (int i = 2; i <= N; i++) {
21+
for (int j = 2; j*j <= i; j++) {
22+
if(i%j == 0){
23+
continue loop;
24+
}
25+
}
26+
primes.add(i);
27+
}
28+
int ans = 0;
29+
int left = 0;
30+
int sum = 0;
31+
for (int right = left; right < primes.size(); right++) {
32+
sum += primes.get(right);
33+
34+
while(sum > N && left <= right){
35+
sum -= primes.get(left++);
36+
}
37+
38+
if(sum == N){
39+
ans++;
40+
}
41+
}
42+
bw.write(ans +"");
43+
bw.close();
44+
}
45+
}
46+
```

0 commit comments

Comments
 (0)