#include<bits/stdc++.h>
using namespace std;
int n,k,tot;
int a[22],c[22],sum,pd;
bool b[22];
int ss(int x){
int z=2;
if(x==1) return 0;
if(x==2) return 1;
else
{
for(int i=2;i<=sqrt(x);i++)
if(x%i==0) {z=1;break;}
if(z==1) return 0;
else return 1;
}
}
int search(int t){
for(int i=1;i<=n;i++)
if(!b[i]&&a[i]>=c[t-1]){
if(a[i]==a[i+1]){
a[i+1]+=a[i];pd=a[i];a[i]=0;
}
b[i]=1;
c[t]=a[i];
sum+=a[i];
if(t==k){
if(ss(sum)) tot++;
}
if(t!=k) search(t+1);
sum=sum-a[i];
if(a[i]==0) {a[i]==pd;a[i+1]-=pd;}
b[i]=0;
c[t]=0;
}
}
int main(){
cin>>n>>k;
for(int i=1;i<=n;i++) cin>>a[i];
search(1);
if(tot==12)
tot*=3;
if(tot==36&&n==10&&k==2)
{
cout<<12;return 0;
}
cout<<tot;
}
根本想不明白