From f69c8e5c42180861c96808a80d00e91e73364dc2 Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Tue, 1 Jul 2025 20:26:33 +0900 Subject: [PATCH] =?UTF-8?q?[20250702]=20BOJ=20/=20G3=20/=20=EC=86=8C?= =?UTF-8?q?=EC=88=98=EC=9D=98=20=EC=97=B0=EC=86=8D=ED=95=A9=20/=20?= =?UTF-8?q?=EC=9D=B4=EA=B0=95=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0 \354\227\260\354\206\215\355\225\251.md" | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 "lkhyun/202507/2 BOJ G3 \354\206\214\354\210\230\354\235\230 \354\227\260\354\206\215\355\225\251.md" diff --git "a/lkhyun/202507/2 BOJ G3 \354\206\214\354\210\230\354\235\230 \354\227\260\354\206\215\355\225\251.md" "b/lkhyun/202507/2 BOJ G3 \354\206\214\354\210\230\354\235\230 \354\227\260\354\206\215\355\225\251.md" new file mode 100644 index 00000000..b9893606 --- /dev/null +++ "b/lkhyun/202507/2 BOJ G3 \354\206\214\354\210\230\354\235\230 \354\227\260\354\206\215\355\225\251.md" @@ -0,0 +1,46 @@ +```java +import java.util.*; +import java.io.*; + +public class Main{ + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + static int N; + static List primes = new ArrayList<>(); + + public static void main(String[] args) throws Exception{ + N = Integer.parseInt(br.readLine()); + if(N == 1){ + bw.write("0"); + bw.close(); + return; + } + + loop: for (int i = 2; i <= N; i++) { + for (int j = 2; j*j <= i; j++) { + if(i%j == 0){ + continue loop; + } + } + primes.add(i); + } + int ans = 0; + int left = 0; + int sum = 0; + for (int right = left; right < primes.size(); right++) { + sum += primes.get(right); + + while(sum > N && left <= right){ + sum -= primes.get(left++); + } + + if(sum == N){ + ans++; + } + } + bw.write(ans +""); + bw.close(); + } +} +```