We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2d2bf48 commit d7d2b53Copy full SHA for d7d2b53
BOJ/1000-5000번/JW_1644.java
@@ -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
+}
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments