比赛 20100927 评测结果 EEEEEWETEE
题目名称 细胞分裂 最终得分 0
用户昵称 maxiem 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-09-27 21:53:20
显示代码纯文本
program cell;
var
  tmp,max,ans,total,n,i,j,m1,m2:longint;
  ff:boolean;
  data:array [1..10000] of longint;
  p:array [1..6000] of word;
  q:array [1..2,1..6000] of record
    v,c:longint;
  end;
  f:array [1..2,1..6000] of boolean;
  qcount:array [1..2] of longint;
  flag:array [1..50000] of boolean;
procedure get;
var
  i,j,t:longint;
begin
  for i:=2 to 223 do begin
    t:=i*i;
    repeat
	  flag[t]:=true;
	  t:=t+i;
    until t>50000;
  end;
  total:=1;i:=3;
  p[total]:=2;
  repeat
    if not(flag[i]) then begin
	  inc(total);
	  p[total]:=i;
	end;
	inc(i,2);
  until i>50000;
end;
procedure expand(no,num:word);
var i:integer;
begin
  qcount[no]:=1;
  while flag[num]=true do begin
    for i:=1 to total do begin
	  if q[no,qcount[no]].c<>0 then inc (qcount[no]);
          if flag[num]=false then break;
	  while num mod p[i]=0 do begin
	    num:=num div p[i];
		q[no,qcount[no]].v:=p[i];
		f[no,p[i]]:=true;
		inc(q[no,qcount[no]].c);
	  end;
	end;
  end;
  f[no,num]:=true;
  q[no,qcount[no]].v:=num;
  q[no,qcount[no]].c:=1;
end;
begin
  fillchar (q,sizeof(q),0);
  fillchar (flag,sizeof(flag),0);
  fillchar (p,sizeof(p),0);
  fillchar (data,sizeof(data),0);
  fillchar (f,sizeof(f),0);
  assign (input,'cell.in');
  reset (input);
  readln (n);
  readln (m1,m2);
  for i:=1 to n do read (data[i]);
  close (input);
  assign (output,'cell.out');
  rewrite (output);
  get;
  expand(1,m1);ans:=maxlongint;
  for i:=1 to qcount[1] do q[1,i].c:=q[1,i].c*m2;
  for i:=1 to n do begin
    fillchar (q[2],sizeof(q[2]),0);
	fillchar (f[2],sizeof(f[2]),0);
    expand(2,data[i]);ff:=true;max:=0;
	for j:=1 to qcount[1] do if (f[1,q[1,j].v]<>f[2,q[1,j].v]) then begin
          if f[1,q[1,j].v] then begin
            ff:=false;
            break;
          end;
	end
	else begin
	  tmp:=q[1,j].c div q[2,j].c;
	  if (q[1,j].c>q[2,j].c) and (q[1,j].c mod q[2,j].c<>0) then inc(tmp);
	  if tmp>max then max:=tmp;
	end;
	if ff then begin
	  if ans>max then ans:=max;
	end;
  end;
  if ans=maxlongint then ans:=-1;
  writeln (ans);
  close (output);
end.