c++16分求调

P1036 [NOIP2002 普及组] 选数

```cpp #include <iostream> #include <vector> using namespace std; int n, k; vector<int> a; int cnt = 0; bool isPrime(int x) { if (x == 1) return false; if (x == 2 || x == 3) return true; for (int i = 2; i * i <= x; i++) { if (x % i == 0) return false; } return true; } void dfs(int num, int sum, int remaining) { if (remaining == 0) { if (isPrime(sum)) { cnt++; } return; } for (int i = num; i < n; i++) { dfs(i + 1, sum + a[i], remaining - 1); } } int main() { cin >> n >> k; a.resize(n); for (int i = 0; i < n; i++) { cin >> a[i]; } dfs(0, 0, k); cout << cnt; return 0; } ```
by CodeAnythingNow @ 2024-05-12 10:45:20


@[__oio__](/user/1112369) @[__oio__](/user/1112369) ```cpp #include <iostream> #include <vector> using namespace std; int n, k; vector<int> a; int cnt = 0; bool isPrime(int x) { if (x == 1) return false; if (x == 2 || x == 3) return true; for (int i = 2; i * i <= x; i++) { if (x % i == 0) return false; } return true; } void dfs(int num, int sum, int remaining) { if (remaining == 0) { if (isPrime(sum)) { cnt++; } return; } for (int i = num; i < n; i++) { dfs(i + 1, sum + a[i], remaining - 1); } } int main() { cin >> n >> k; a.resize(n); for (int i = 0; i < n; i++) { cin >> a[i]; } dfs(0, 0, k); cout << cnt; return 0; } ```
by CodeAnythingNow @ 2024-05-12 10:46:40


@[songhongjin](/user/1135135) 老师泥哲。。。
by __oio__ @ 2024-05-12 10:47:31


[我](https://www.luogu.com.cn/user/1135135#practice)刚到洛谷
by CodeAnythingNow @ 2024-05-12 10:50:14


我这代码在逻辑上是正确的(doge)
by CodeAnythingNow @ 2024-05-12 10:53:43


```cpp #include<bits/stdc++.h> using namespace std; bool isprime(int n){ if(n<2){ return 0; } for(int i=2;i*i<=n;i++){ if(n%i==0){ return 0; } } return 1; } int a[105]; int main(){ int n; cin>>n; for(int i=1;i<=n;i++){ cin>>a[i]; if(isprime(a[i])){ cout<<a[i]<<" "; } } return 0; } ``` AC
by E303 @ 2024-05-12 11:10:33


@[E303](/user/1106358) 已关QwQ
by __oio__ @ 2024-05-13 19:46:48


@[E303](/user/1106358) AC个蛋啊!!!
by LYZ0602 @ 2024-06-02 16:01:19


@[LYZ0602](/user/1246191) 扶额苦笑,其实我没看懂(悄咪咪
by __oio__ @ 2024-06-02 19:50:54


@[LYZ0602](/user/1246191) 衮衮衮'!'*10^999999 我都能AC 你怎么不能
by E303 @ 2024-06-02 21:21:45


| 下一页