From cf1582c632b557e000ee99dcf588ee268ebcae22 Mon Sep 17 00:00:00 2001 From: sh0723 Date: Sun, 12 Jul 2026 16:37:43 +0900 Subject: [PATCH] =?UTF-8?q?1644=20:=20=EC=86=8C=EC=88=98=EC=9D=98=20?= =?UTF-8?q?=EC=97=B0=EC=86=8D=ED=95=A9=20solve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/week5/BOJ1644/BOJ1644_V1.cpp | 43 ++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/week5/BOJ1644/BOJ1644_V1.cpp diff --git a/src/week5/BOJ1644/BOJ1644_V1.cpp b/src/week5/BOJ1644/BOJ1644_V1.cpp new file mode 100644 index 0000000..d2b8aec --- /dev/null +++ b/src/week5/BOJ1644/BOJ1644_V1.cpp @@ -0,0 +1,43 @@ +#include +using namespace std; +bool a[4000001]; +int arr[200001]; +int p=0; +int main() { + + ios_base::sync_with_stdio(false); + cin.tie(nullptr); + cout.tie(nullptr); + + + int n; + cin >> n; + + for (int i=2; i<=n; i++) { + if (a[i]) continue; + for (int j=2*i; j<=n; j+=i) { + a[j] = true; + } + } + + for (int i=2; i<=n; i++) { + if (!a[i]) arr[p++] = i; + } + + int ret = 0; + int sum = 0; + int st = 0, ed = 0; + while(true) { + if (sum >= n) { + if (sum == n) ret++; + sum -= arr[st++]; + } else { + if (ed == p) break; + sum += arr[ed++]; + } + } + + cout << ret << '\n'; + + return 0; +} \ No newline at end of file