From b43b4b9e157909583e6e2936b8d6bbed5fed28a3 Mon Sep 17 00:00:00 2001 From: Jihoon Lee Date: Sat, 6 Jul 2024 15:56:10 +0900 Subject: [PATCH] Add 19699.cpp --- 19xxx/19699.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 19xxx/19699.cpp diff --git a/19xxx/19699.cpp b/19xxx/19699.cpp new file mode 100644 index 00000000..b1360251 --- /dev/null +++ b/19xxx/19699.cpp @@ -0,0 +1,56 @@ +#include +#include +#include +using namespace std; + +int n, m; +vector h; +vector prime; +set ans; + +vector sieve(int n) { + vector prime(n+1, true); + prime[0] = prime[1] = false; + for (int i=4; i<=n; i+=2) { + prime[i] = false; + } + + for (int i=3; i*i<=n; i+=2) { + if (!prime[i]) continue; + for (int j=i*i; j<=n; j+=i*2) { + prime[j] = false; + } + } + return prime; +} + +void backtrack(int cnt, int idx, int sum) { + if (cnt == m) { + if (prime[sum]) ans.insert(sum); + return; + } + + for (int i=idx; i> n >> m; + h.resize(n); + for (int i=0; i> h[i]; + + backtrack(0, 0, 0); + + if (ans.empty()) ans.insert(-1); + for (int a : ans) cout << a << " "; +} + +int main(void) { + ios::sync_with_stdio(false); + cin.tie(nullptr); + + prime = sieve(9000); + solve(); + return 0; +} \ No newline at end of file