hiho week 167 register

Ended

Participants:334

Verdict:Accepted
Score:100 / 100
Submitted:2017-09-12 23:37:37

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int n;
int p[105],s[600005][105];
int gcd(int n,int m){if(n%m==0) return m; return gcd(m,n%m);}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++) cin>>p[i];
    ll ans=1;
    for(int i=1;i<=n;i++){
        int k=1,r=i;    
        while(p[r]!=i)r=p[r],k++;
        ans=ans*k/gcd(ans,k);
    }
    cout<<ans<<endl;
    return 0;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX