比赛 20101117 评测结果 AAAATTTTTA
题目名称 教官 最终得分 50
用户昵称 donny 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-17 08:46:51
显示代码纯文本
program officer;
var
  a,b:array[0..10000]of longint;
  c:array[1..10000]of boolean;
  i,j,k,l:longint;
  n,m,p:longint;
  e:boolean;
procedure search(const x,y:longint);
begin
  if x=i then
  begin
    inc(b[0]);
    b[b[0]]:=y;
  end
  else
  begin
    c[x]:=true;
    search(a[x],y+1);
  end;
end;
begin
  assign(input,'officer.in');
  reset(input);
  assign(output,'officer.out');
  rewrite(output);
  readln(n);
  for i:=1 to n do
    readln(a[i]);
  for i:=1 to n do
    if c[i]=false then
      search(a[i],1);
  m:=0;
  for i:=1 to b[0] do
    if b[i]>m then m:=b[i];
  for i:=1 to b[0]-1 do
    for j:=i+1 to b[0] do
      if b[i]=b[j] then
      begin
        dec(b[0]);
        for k:=j to b[0] do
          b[j]:=b[j+1];
      end;
  i:=1;
  repeat
    p:=m*i;
    e:=false;
    for j:=1 to b[0] do
      if (p mod b[j])<>0 then
      begin
        e:=true;
        break;
      end;
    if e=false then break;
    inc(i);
  until 1=2;
  writeln(p);
  close(input);
  close(output);
end.