DFSQz 16pts QwQ
查看原帖
DFSQz 16pts QwQ
1286053
Nostopathy楼主2024/6/8 09:24
#include <iostream>
using namespace std;
int a[23], n, k, m;
int zs(int x){for(int i=2; i*i<=x; ++i) if(x%i==0) return 0; return 1;}
void dfs(int cs, int he, int id){
	if(cs==n && zs(he)){m++; return;}
	if(id>n) return;
	for(int i=id; i<=n; ++i) dfs(cs+1, he+a[i], i+1);
	dfs(cs, he, id+1);
}
int main(){
	cin>>n>>k;
	for(int i=1; i<=n; ++i) cin>>a[i];
	dfs(0, 0, 1);
	cout<<m;
}
2024/6/8 09:24
加载中...