Title Description
Description
n integers are known to x1,x2,..., xn, and an integer k (k 3+7+12=22 3+7+19=29 7+12+19=38 3+12+19=34.
Now, ask you to figure out how many kinds of numbers are in total.
For example, in the above example, there is only one and a prime number: 3+7+19=29).
Enter a description
Input Description
Keyboard input, in the form of:
N, K (1<=n<=20,k X1,X2,...,XN (1<=xi<=5000000)
Output description
Output Description
Screen output in the form of:
An integer (the number of species that satisfies the condition).
Sample input
Sample Input
4 3
3 7 12 19
Sample output
Sample Output
1
Data range and Tips
Data Size & Hint
(1<=n<=20,k (1<=xi<=5000000)
Exercises
Search + primes.
Recursive search for each number: two possible (optional), choose to add to the inside, do not choose to skip. Finally, we will find some and, judging these and is not a prime number on the line.
var n,m,i,ans:longint;
A:array[0..21]of Longint;
Procedure Dfs (K,s,sum:longint);
var i:longint;
Begin
If S=m Then
Begin
For i:=2 to Trunc (sqrt (sum)) do
If sum mod i=0 then exit;
Inc (ANS);
Exit
End
If K=n+1 then exit;
DFS (K+1,s+1,sum+a[k]);
DFS (k+1,s,sum);
End
Begin
READLN (N,M);
For I:=1 to n do read (A[i]);
DFS (1,0,0);
Write (ANS);
End.
2002 Select number