题目地址:http://codevs.cn/problem/1008/
分析:
深搜
代码:
var
n,k,i,j,t,sum:longint;
p:boolean;
a:array[0..20]of longint;
b:array[0..20]of longint;
begin
t:=0;
p:=false;
read(n,k);
readln;
for i:=1 to n do read(a[i]);
readln;
for i:=1 to k do b[i]:=i;
b[0]:=0;
while(b[0]=0)do
begin
p:=false;
sum:=0;
j:=k;
while(b[j]=n-k+j)do dec(j);
b[j]:=b[j]+1;
for i:=j+1 to k do b[i]:=b[i-1]+1;
for i:=1 to k do sum:=sum+a[b[i]];
for i:=2 to trunc(sqrt(sum)) do
begin
if(sum mod i=0)then
begin
p:=true;
break;
end;
end;
if(not(p))then t:=t+1;
end;
writeln(t);
end.