记录编号 19192 评测结果 AAAAAAAAAA
题目名称 [NOIP 2009]细胞分裂 最终得分 100
用户昵称 Gravatar苏轼 是否通过 通过
代码语言 Pascal 运行时间 0.037 s
提交时间 2010-09-29 13:00:39 内存使用 0.23 MiB
显示代码纯文本
program cell(input,output);

var
  n,m1,m2,si,i,j,max,min,len,tmp:longint;
  count,fj:array[1..10000]of longint;
  prime:array[0..10000]of longint;

procedure makeprime;
  var
    i:longint;
    boo:boolean;
  begin
    prime[0]:=1;
    prime[1]:=2;

    for i:=3 to 10000 do
    begin
      boo:=true;

      for j:=1 to prime[0] do
      begin
        if prime[j]>sqrt(i) then
          break;

        if i mod prime[j]=0 then
        begin
          boo:=false;
          break;
        end;
      end;

      if boo then
      begin
        inc(prime[0]);
        prime[prime[0]]:=i;
      end;
    end;
  end;

begin
  assign(input,'cell.in');
  reset(input);

  assign(output,'cell.out');
  rewrite(output);

  readln(n);
  readln(m1,m2);

  makeprime;

  for i:=1 to 50000 do
  begin
    while m1 mod prime[i]=0 do
    begin
      inc(count[i]);
      m1:=m1 div prime[i];
    end;

    count[i]:=count[i]*m2;

    if m1=1 then
    begin
      len:=i;
      break;
    end;
  end;

  min:=maxlongint;
  for i:=1 to n do
  begin
    read(si);
    max:=-1;

    for j:=1 to 50000 do
    begin
      fj[j]:=0;

      while si mod prime[j]=0 do
      begin
        inc(fj[j]);
        si:=si div prime[j];
      end;

      if (fj[j]<>0)and(fj[j]<=count[j]) then
      begin
        if (fj[j]<>count[j])and(count[j] div fj[j]>max) then
        begin
          if (count[j] mod fj[j]=0) then
            m1:=-1
          else
            m1:=0;

          if count[j] div fj[j]+m1>max then
            max:=count[j] div fj[j]+m1;
        end;
      end
      else if (count[j]<>0)and(fj[j]=0) then
      begin
        max:=maxlongint;
        break;
      end;

      if (si=1)or(j=len) then
      begin
        tmp:=j;
        break;
      end;
    end;

    if tmp<len then
      max:=maxlongint;

    if (max<min)or(min=-1) then
      min:=max;
  end;

  if min<maxlongint then
    writeln(min+1)
  else
    writeln(-1);

  close(input);
  close(output);
end.