比赛 20101117 评测结果 AAETEEWEEA
题目名称 教官 最终得分 30
用户昵称 1102 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-17 09:12:41
显示代码纯文本
program xxx;
var a:array[1..10000,0..1] of longint;
    n,i,s:longint;


procedure find(x:longint);
var j,w:longint;
begin
  j:=0;
  w:=x;
  repeat
    begin
      inc(j);
      w:=a[w,0];
      if w=x then
        break;
    end
  until j=maxlongint;
  a[x,1]:=j;
end;

function min(x,y:longint):longint;
begin
  if x>y then
    min:=y
  else
    min:=x;
end;

function max(x,y:longint):longint;
begin
  if x>y then
    max:=x
  else
    max:=y;
end;


function yueshu(x,y:longint):longint;
var w:longint;
begin
  w:=max(x,y);
  y:=min(x,y);
  x:=w;
  repeat
    begin
      if (x mod y=0) then
        begin
          yueshu:=y;
          break;
        end
      else
        begin
          w:=y;
          y:=x mod y;
          x:=w;
        end;
    end
  until x<0;
end;

function beishu(x,y:longint):longint;
begin
  beishu:=(x*y) div yueshu(x,y);
end;




begin
  assign(input,'officer.in');
  reset(input);
  assign(output,'officer.out');
  rewrite(output);
  read(n);
  for i:=1 to n do
    read(a[i,0]);
  for i:=1 to n do
    find(i);
  s:=a[1,1];
  for i:=1 to n-1 do
    s:=beishu(s,a[i+1,1]);
  write(s);
  close(input);
  close(output);
end.