WA in GARDEN GAME

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

THIS IS MY CODE

Please help

  1. What is use of the loop that has the array a[]?

    I don’t think there is any use of this while loop.

    So, remove it.

  2. Also, you are not taking (lcm)%1000000007 at each step.

  3. There were also many small errors like use of %d instead of %lld for long long in scanf().

  4. Your algorithm for finding the factors was also very complex. I changed it.

  5. Try to correct your code for factors() function.

  6. You are declaring max as global. This needs to inside while(t–) loop so that it is initially zero for all test cases.

  7. There is no need to use pow function, a simple for loop will work.

I have corrected your code: Click Here


1 Like

Thanks a lot for going through my code.
and providing me such a detail analysis of my code and silly mistakes.
Learnt a lot
thanks.

welcome
Happy coding