|
- #include<iostream>
- #include<cmath>
- using namespace std;
- int a[25];
- int n,k,ans;
- bool zs(int x){
- if (x<2) return false;
- for (int i=2;i<=sqrt(x);i++)
- if(x%i==0) return false;
- return true;
- }
- void search(int total,int i,int m){
- if (m==k&&zs(total)) ans++;
- if (m<k&&k-m<n-i+1) {
- search(total+a[i],i+1,m+1);
- search(total,i+1,m);
- }
- if (m<k&&k-m>=n-i+1) search(total+a[i],i+1,m+1);
- }
- int main(){
- cin>>n>>k;
- for (int i=1;i<=n;i++) cin>>a[i];
- search(0,1,0);
- cout<<ans<<endl;
- return 0;
- }
复制代码 |
|