记录编号 395245 评测结果 AAAAAAAAAA
题目名称 教官 最终得分 100
用户昵称 GravatarHeHe 是否通过 通过
代码语言 C++ 运行时间 1.436 s
提交时间 2017-04-15 11:28:49 内存使用 0.47 MiB
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

typedef long long LL;

const int MAXN = 1e4 + 10;

inline int in(void){ 
	char tmp = getchar();
	int res = 0;
	while(!isdigit(tmp))tmp = getchar();
	while(isdigit(tmp))
		res = (res + (res << 2) << 1) + (tmp ^ 48),
		tmp = getchar();
	return res;
}

inline LL gcd(LL a, LL b);
inline LL lcm(LL a, LL b);

int N;
LL g[MAXN], k[MAXN];

int main(){ 
#ifndef LOCAL
	freopen("officer.in", "r", stdin);
	freopen("officer.out", "w", stdout);
#else
	freopen("test.in", "r", stdin);
#endif
	N = in();
	for(int i = 1; i <= N; ++i)g[i] = in();
/*	int a = in(), b = in();
	printf("%d", gcd(a, b));*/

	for(int i = 1; i <= N; ++i){ 
		k[i] = 1;
		for(int j = g[i]; j != i; j = g[j])++k[i];
	}
	LL ans = k[1];
	for(int i = 2; i <= N; ++i){ 
		ans = lcm(ans, k[i]);
	}

	printf("%lld", ans);
	
	return 0;
}

inline LL gcd(LL a, LL b){ 
	static LL c;
	while(b){ 
		c = b;
		b = a % b;
		a = c;
	}
	return a;
}

inline LL lcm(LL a, LL b){ 
	return (a / gcd(a, b)) * b;
}