比赛 暑假培训一 评测结果 AAAAA
题目名称 选数 最终得分 50
用户昵称 lc 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-07-17 11:29:49
显示代码纯文本
program ex002;
 var
     f:array[1..10000] of boolean;
     pp:array[0..1229] of integer;
     n,m,i:integer;
     ans:longint;
     num:array[1..20] of longint;
     a:array[0..20] of integer;


 function prime(i:longint):boolean;
  var
      j:longint;
  begin
   if i<=10000 then if f[i] then exit(true) else exit(false);
   for j:=1 to 1229 do
   begin
   if pp[j]>trunc(sqrt(i))
   then break;
   if i mod pp[j]=0 then exit(false);
   end;
   exit(true);
  end;


 procedure init;
  var
     i,j:integer;
  begin
  fillchar(f,sizeof(f),1);
  f[1]:=false;

  for i:=1 to 10000 do
   if f[i]
   then
   begin
   j:=i*2;
  while j<=10000 do
   begin
   f[j]:=false;
   inc(j,i);
   end;
   end;

  for i:=2 to 10000 do
  if f[i]
  then
      begin
      inc(pp[0]);
      pp[pp[0]]:=i
      end;

  end;




 procedure print;
  var
      total:longint;
      i:integer;
  begin
   total:=0;
   for i:=1 to m do
   inc(total,num[a[i]]);
   if prime(total)
   then inc(ans);

  end;



 procedure dfs(k:integer);
   var
    i:integer;
  begin
  if k>m then begin print; exit end;
   for i:=a[k-1]+1 to n-m+k do
    begin
    a[k]:=i;
    dfs(k+1);
    end;
 end;


 begin
 assign(input,'choose.in');
 assign(output,'choose.out');
 reset(input); rewrite(output);
 init;
 read(n,m);
 for i:=1 to n do read(num[i]);
 a[0]:=0;
 dfs(1);
 writeln(ans);
 close(input); close(output);
 end.