I am trying to solve GARDEN GAME problem

first i am trying to find length of cycles using concept similar in PCYCLE

then i am making an array containing maximum powers of all prime factors of lengths of cycles to calculate LCM as mentioned in GARDEN GAME EDITORIAL

my code is giving right answer for the test cases i have tried

yet it is giving WA after submiting

Please help