比赛 |
20101117 |
评测结果 |
AATTWTATWA |
题目名称 |
教官 |
最终得分 |
40 |
用户昵称 |
wo shi 刘畅 |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2010-11-17 09:50:34 |
显示代码纯文本
- var
- i,c,n:longint;
- total:int64;
- a,f:array[0..20000]of longint;
- ans:array[0..20000]of int64;
-
- function gcd(x,y:int64):int64;
- begin
- if y=0 then gcd:=x
- else gcd:=gcd(y,x mod y);
- end;
-
- procedure go(k:longint);
- begin
- if (total>0)and(k=i) then exit;
- total:=total+1;
- go(a[k]);
- end;
-
- begin
- assign(input,'officer.in'); reset(input);
- assign(output,'officer.out'); rewrite(output);
- readln(n);
- for i:=1 to n do read(a[i]);
- for i:=1 to n do
- begin
- total:=0;
- go(i);
- f[i]:=total;
- end;
- ans[1]:=f[1];
- for i:=2 to n do
- begin
- c:=gcd(ans[i-1],f[i]);
- ans[i]:=(ans[i-1]*f[i]) div c;
- end;
- writeln(ans[n]);
- close(input);
- close(output);
- end.