比赛 20101117 评测结果 AAATAAAAAA
题目名称 教官 最终得分 90
用户昵称 wangwangdog 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2010-11-17 11:26:40
显示代码纯文本
#include<stdio.h>
long long step,a[10001],d[10001],i,oo,n,pos;
long long make(long long a,long long b)
{long long q;
	if(b>a){long long pp=a;a=b;b=pp;}
	do
    {
		q=a%b;
		a=b;
		b=q;
    }while(q!=0);
	return a;
}
int main()
{
	FILE *fin,*fout;
	fin=fopen("officer.in","rb");
	fout=fopen("officer.out","wb");
	fscanf(fin,"%lld\n",&n);
	for(i=1;i<=n;i++)
	{
		fscanf(fin,"%lld\n",&a[i]);
		
	}
	for(i=1;i<=n;i++)
	{
		pos=i;
		step=1;
		pos=a[i];
		
		while(pos!=i)
		{
			pos=a[pos];
			step++;
		}
		
		d[i]=step;
	}
	for(i=1;i<=n-1;i++)
	{
		oo=make(d[i],d[i+1]);
		d[i+1]=d[i+1]/oo*d[i];
	}
	fprintf(fout,"%lld",d[n]);
	fclose(fin);
	fclose(fout);
	return 0;
}