16分代码求调
查看原帖
16分代码求调
1650500
nullpt3楼主2025/1/21 11:45
#include<bits/stdc++.h>
using namespace std;
int n,a[1000001],k,h=0,v[10000001],s=0;
bool check(int x){
	for(int i=2;i<=x-1;i++){
		if(x%i==0){
			return false;
		}
	}
	return true;
}

void dfs(int x,int y){
	if(x==k){
		if(check(h)){
			s++;
		}
	}
	else{
		for(int i=y;i<=n;i++){
			if(!v[i]){
				v[i]=1;
				h=h+a[i];
				dfs(x+1,y+1);
				v[i]=0;
				h=h-a[i];
			}
		}
	}
}

int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	dfs(0,1);
	cout<<s;
}
2025/1/21 11:45
加载中...