比赛 20101117 评测结果 WAETWEWEEW
题目名称 教官 最终得分 10
用户昵称 maxiem 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-17 08:58:21
显示代码纯文本
program officer;
var
  data:array [1..10000] of integer;
  step:array [1..10000] of int64;
  n,i,now:longint;
  t1,t2:int64;
function gcd(a,b:longint):longint;
var tmp:longint;
begin
  if a<b then begin
    tmp:=a;
	a:=b;
	b:=tmp;
  end;
  if b=0 then exit(a);
  while b>0 do begin
    tmp:=a mod b;
	a:=b;
	b:=tmp;
  end;
  exit(a);
end;
begin
  assign (input,'officer.in');
  reset (input);
  readln (n);
  for i:=1 to n do readln (data[i]);
  close (input);
  assign (output,'officer.out');
  rewrite (output);
  fillchar (step,sizeof(step),0);
  for i:=1 to n do begin
    now:=data[i];step[i]:=1;
	if now=i then step[i]:=0 else begin
	  while now<>i do begin
	    now:=data[now];
	    step[i]:=step[i]+1;
	  end;
	end;
  end;
  for i:=2 to n do begin
    t1:=step[i]*step[i-1];
    t2:=gcd(step[i],step[i-1]);
	step[i]:=t1 div t2;
  end;
  writeln (step[n]);
  close (output);
end.