2283: Prime Sums

2283: Prime Sums


ResultTIME LimitMEMORY LimitRun TimesAC TimesJUDGE
3s8192K396115Standard
There is a set S = {x1, x2, ..., xN} and a integer K, can you tell me how many sums of K integers in S which the sums are all primes?

Input

There are several case in the input. For each case there are two lines, the first line consist of a integer N(1 <= N <= 20) and the integer K(1 <= K <= N), the second line is N integers x1, x2, ..., xN (1 <= xi <= 5000000).

Output

Please output the number of the sums which are all primes in a single line for each case.

Sample Input

3 2
7 6 5

Sample Output

2

 

Problem Source: windsbu

 


This problem is used for contest: 43  153 

 

 

#include<stdio.h>
#include<math.h>
int num[30],ans[30];
int n,k;
int count;
bool prime(int l)
{
    //if(l==2) return true;
    //if(l%2==0) return true;
    int i; double k=sqrt(l*1.0);
    for(i=2;i<=k;i++)
    {
        if(l%i==0) return false ;
    }
    return true;
}
void dfs(int x,int step)
{
    int i;
    if(step==k)
    {
        int sum=0;
        for(i=0;i<k;i++) sum+=num[i];
        if(prime(sum)) count++;
       // printf("%d   ..%d    /n",sum,prime(sum));
        return ;
    }
    if(x==n) return ;
    num[step]=ans[x];
    dfs(x+1,step+1);
    dfs(x+1,step);
}
int main()
{
    int i;
    while(scanf("%d%d",&n,&k)==2)
    {
        for(i=0;i<n;i++) scanf("%d",&ans[i]);
        count=0;
        dfs(0,0);
        printf("%d/n",count);
    }
    return 0;
}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值