求助! 代码如下:
//C++
#include <bits/stdc++.h>
using namespace std;
static int total, chosen, numbers[22], chosenArray[22];
int counter = 0;
void search(int depth) {
//int judge = 0;
if (depth == chosen) {
int sum = 0;
for (int i = 0; i < chosen; ++i) {
sum += chosenArray[i];
}
if (sum == 2) {
counter++;
return;
} else if (sum > 2) {
for (int i = 2; i * i <= sum; ++i) {
if (sum % i == 0) {
return;
}
}
counter++;
}
return;
}
for (int i = 0; i < total; ++i) {
chosenArray[depth] = numbers[i];
search(depth + 1);
/*
if (depth > 1) {
for (int j = 0; j < i; ++j) {
if (chosenArray[j] == chosenArray[depth]) {
judge = 1;
}
}
}
if (judge == 0) {
search(depth + 1);
}
judge = 0;
*/
}
}
int main() {
ios::sync_with_stdio(false);
cin >> total;
for (int i = 0; i < total; ++i) {
cin >> numbers[i];
}
search(0);
cout << counter;
}