题目:
代码:
#include<iostream>
using namespace std;
# define M 500
#include<algorithm>int sa[100005],k,n,count1;bool func(int n)
{int mark=0;if(n==1){return 1;}else{for(int i=2;i<=n-1;i++){if(n%i==0){mark=1;return 0;}}if(mark==0)return 1;}}void dfs(int step,int sum,int start)
{if(step==k+1){if(func(sum)){if(func(sum)){count1++;}}}for(int i=start;i<=n;i++){dfs(step+1,sum+sa[i],i+1);}
}int main()
{//不重复遍历 start和i打配合(实现每次遍历后面的)cin>>n>>k;for(int i=1;i<=n;i++){cin>>sa[i];}dfs(1,0,1);cout<<count1<<endl;
}