#include <stdio.h>
int lcm ( int a, int b ){
int x=a;
int y=b;
int c;
while ( a != 0 ) {
c = a; a = b%a; b = c;
}
return (x*y)/b;
}
int sgarden(int n,int a[]){
int i=1;
int ops=a[n];
while(ops!=n){
ops=a[ops];
i++;
}//while
return i;
}
int main()
{
int i,maxp=1;
int a[]={2,3,1,5,4};
for(i=0;i<(sizeof(a)/sizeof(int));i++){a[i]--;}
for(i=0;i<(sizeof(a)/sizeof(int));i++){
int count = sgarden(i,a);
maxp=lcm(count,maxp);
}//for
printf("Max permutations %d",maxp
); return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CmludCBsY20gKCBpbnQgYSwgaW50IGIgKXsKICAgIGludCB4PWE7CiAgICBpbnQgeT1iOwogICAgaW50IGM7IAogICAgd2hpbGUgKCBhICE9IDAgKSB7IAogICAgICAgIGMgPSBhOyBhID0gYiVhOyAgYiA9IGM7CiAgICAgICAgfSAKICAgIHJldHVybiAoeCp5KS9iOyAKICAgIAp9CgppbnQgc2dhcmRlbihpbnQgbixpbnQgYVtdKXsKICAgIGludCBpPTE7CiAgICBpbnQgb3BzPWFbbl07IAogICAgd2hpbGUob3BzIT1uKXsKICAgICAgICBvcHM9YVtvcHNdOwogICAgICAgIGkrKzsKICAgIH0vL3doaWxlCnJldHVybiBpOwp9CgppbnQgbWFpbigpCnsKaW50IGksbWF4cD0xOwppbnQgYVtdPXsyLDMsMSw1LDR9Owpmb3IoaT0wO2k8KHNpemVvZihhKS9zaXplb2YoaW50KSk7aSsrKXthW2ldLS07fQpmb3IoaT0wO2k8KHNpemVvZihhKS9zaXplb2YoaW50KSk7aSsrKXsKaW50IGNvdW50ID0gc2dhcmRlbihpLGEpOwptYXhwPWxjbShjb3VudCxtYXhwKTsKCn0vL2ZvcgpwcmludGYoIk1heCBwZXJtdXRhdGlvbnMgJWQiLG1heHApOwpyZXR1cm4gMDsKfQoKCg==