比赛 20101117 评测结果 AATTWTATWA
题目名称 教官 最终得分 40
用户昵称 wo shi 刘畅 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-17 09:50:34
显示代码纯文本
  1. var
  2. i,c,n:longint;
  3. total:int64;
  4. a,f:array[0..20000]of longint;
  5. ans:array[0..20000]of int64;
  6.  
  7. function gcd(x,y:int64):int64;
  8. begin
  9. if y=0 then gcd:=x
  10. else gcd:=gcd(y,x mod y);
  11. end;
  12.  
  13. procedure go(k:longint);
  14. begin
  15. if (total>0)and(k=i) then exit;
  16. total:=total+1;
  17. go(a[k]);
  18. end;
  19.  
  20. begin
  21. assign(input,'officer.in'); reset(input);
  22. assign(output,'officer.out'); rewrite(output);
  23. readln(n);
  24. for i:=1 to n do read(a[i]);
  25. for i:=1 to n do
  26. begin
  27. total:=0;
  28. go(i);
  29. f[i]:=total;
  30. end;
  31. ans[1]:=f[1];
  32. for i:=2 to n do
  33. begin
  34. c:=gcd(ans[i-1],f[i]);
  35. ans[i]:=(ans[i-1]*f[i]) div c;
  36. end;
  37. writeln(ans[n]);
  38. close(input);
  39. close(output);
  40. end.