记录编号 22257 评测结果 AAAAAAAAAA
题目名称 最终得分 100
用户昵称 Gravatardonny 是否通过 通过
代码语言 Pascal 运行时间 0.154 s
提交时间 2010-11-18 12:02:44 内存使用 0.11 MiB
显示代码纯文本
program eight;
var
  i,j,k,l:longint;
  a,b:int64;
  s:array[1..20]of longint;
  n:longint;
  max:int64;
  m:array[1..20]of boolean;
  w:array[0..20]of longint;
function gbs(const x,y:int64):int64;
var
  a,b,c,d:int64;
begin
  a:=x;
  b:=y;
  d:=a*b;
  c:=a mod b;
  while c<>0 do
  begin
    a:=b;
    b:=c;
    c:=a mod b;
  end;
  exit(d div b);
end;
procedure search(const x,y:longint);
var
  i,j:longint;
  p,q:int64;
  v:boolean;
begin
  if w[0]=y then
  begin
    v:=false;
    q:=8;
    for i:=1 to w[0] do
    begin
      q:=gbs(q,s[w[i]]);
      if q>b then
      begin
        v:=true;
        break;
      end;
    end;
    if (not v) then
    begin
      if (a mod q)=0 then
        p:=a div q
        else p:=(a div q)+1;
      p:=(b div q)-p+1;
      if (y mod 2)=1 then
        max:=max-p
        else max:=max+p;
    end;
  end
  else
  begin
  if (n-x+1)>=(y-w[0]) then
  begin
    for i:=x to n do
      if m[i]=false then
      begin
        inc(w[0]);
        w[w[0]]:=i;
        m[i]:=true;
        search(i+1,y);
        w[w[0]]:=0;
        dec(w[0]);
        m[i]:=false;
      end;
  end;
  end;
end;
procedure go;
var
  i,j,k,l:longint;
begin
  for i:=1 to n do
  begin
    for j:=1 to n do
      m[j]:=false;
    for j:=1 to 20 do
      w[j]:=0;
    w[0]:=0;
    search(1,i);
  end;
end;
begin
  assign(input,'eight.in');
  reset(input);
  assign(output,'eight.out');
  rewrite(output);
  readln(n);
  for i:=1 to n do
    read(s[i]);
  readln;
  readln(a,b);
  if (a mod 8)=0 then max:=a div 8
  else max:=(a div 8)+1;
  max:=(b div 8)-max;
  go;
  writeln(max+1);
  close(input);
  close(output);
end.