比赛 20101117 评测结果 AAATAAAAAA
题目名称 教官 最终得分 90
用户昵称 ybh 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-17 09:04:20
显示代码纯文本
{教官 NOIP模拟2010-11-17
 Author: yangbohua
 Time: 2010-11-17}

program officer;
var
  a:array[0..10001] of longint;
  f:array[0..10001] of int64;
  n,i,x:longint;
  ans:int64;

function gcd(y,z:int64):int64;
begin
  if z=0
    then gcd:=y
    else gcd:=gcd(z,y mod z);
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]);
  fillchar(f,sizeof(f),0);
  for i:=1 to n do
  begin
    x:=i;
    repeat
      x:=a[x];
      f[i]:=f[i]+1;
    until x=i;
  end;
  ans:=f[1];
  for i:=2 to n do
  begin
    ans:=(ans div gcd(ans,f[i]))*f[i];
  end;
  writeln(ans);
  close(input);
  close(output);
end.