Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d7d2b53

Browse files
committed
백제완: [BOJ] 1644 소수의 연속합_250329
1 parent 2d2bf48 commit d7d2b53

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

‎BOJ/1000-5000번/JW_1644.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import java.util.ArrayList;
2+
3+
public class JW_1644 {
4+
5+
public static void main(String[] args) throws Exception {
6+
int n = read();
7+
int cnt = 0;
8+
boolean[] isPrime = new boolean[n + 1];
9+
isPrime[0] = isPrime[1] = true;
10+
ArrayList<Integer> prime = new ArrayList<>();
11+
for (int i = 2; i < n + 1; i++) {
12+
if (isPrime[i])
13+
continue;
14+
prime.add(i);
15+
for (int j = i * 2; j < n + 1; j += i)
16+
isPrime[j] = true;
17+
}
18+
int l = 0, r = 0, sum = 0;
19+
while (r < prime.size()) {
20+
sum += prime.get(r);
21+
while (sum > n && l <= r)
22+
sum -= prime.get(l++);
23+
if (sum == n)
24+
cnt++;
25+
r++;
26+
}
27+
System.out.println(cnt);
28+
}
29+
30+
private static int read() throws Exception {
31+
int c, n = System.in.read() & 15;
32+
while ((c = System.in.read()) >= 48)
33+
n = (n << 3) + (n << 1) + (c & 15);
34+
return n;
35+
}
36+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /