记录编号 19040 评测结果 AAAAAAAAAA
题目名称 [NOIP 2009]细胞分裂 最终得分 100
用户昵称 Gravatarmaxiem 是否通过 通过
代码语言 Pascal 运行时间 0.123 s
提交时间 2010-09-28 08:27:41 内存使用 0.29 MiB
显示代码纯文本
program cell;
var
  sum,ans,max,tmp,total,n,m1,m2,count,i,j,t:longint;
  f:boolean;
  data:array [1..10000] of longint;
  flag:array [1..50000] of boolean;
  s,p:array [1..6000] of longint;
  q:array [1..6000] of record
    v,c:longint;
  end;
procedure get;
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;
var m,i:longint;
begin
  m:=m1;
  count:=0;
  for i:=1 to total do begin
    if flag[m]=false then break;
    if m mod p[i]=0 then begin
	  inc(count);
	  q[count].v:=p[i];
	  q[count].c:=1;
	  m:=m div p[i];
	end;
    while m mod p[i]=0 do begin
	  inc(q[count].c);
	  m:=m div p[i];
	end;
  end;
  if m<>1 then begin
    inc(count);
	q[count].v:=m;
	q[count].c:=1;
  end;
end;
begin
  get;
  assign (input,'cell.in');
  reset (input);
  fillchar (q,sizeof(q),0);
  readln (n);
  readln (m1,m2);
  for i:=1 to n do read (data[i]);
  close (input);
  assign (output,'cell.out');
  rewrite (output);
  ans:=maxlongint;
  if m1=1 then begin
    writeln (0);
    close (output);
    halt;
  end
  else expand;
  for i:=1 to count do q[i].c:=q[i].c*m2;
  for i:=1 to n do begin
    tmp:=data[i];f:=true;max:=0;
    fillchar (s,sizeof(s),0);
    if data[i]<>1 then begin
    for j:=1 to count do begin
	  if tmp mod q[j].v=0 then begin
	    s[j]:=1;
            tmp:=tmp div q[j].v;
		while tmp mod q[j].v=0 do begin
                  inc(s[j]);
                  tmp:=tmp div q[j].v;
                end;
	  end
	  else begin
	    f:=false;
		break;
	  end;
	  if s[j]<q[j].c then begin
	    sum:=q[j].c div s[j];
	    if q[j].c mod s[j]<>0 then inc(sum);
		if sum>max then max:=sum;
	  end;
	end;
	if f then if max<ans then ans:=max;
    end;
  end;
  if ans=maxlongint then ans:=-1;
  writeln (ans);
  close (output);
end.