SGARDEN - Editorial

Cycles finding is similar to this : PCYCLE Problem - CodeChef

1 Like

java biginteger is really useful :smiley: :stuck_out_tongue:

3 Likes

use prime factorization to find LCM.

1 Like

Wonā€™t taking mod each time give the wrong answer?

3 Likes

Hi All , The last pseudo code is wrong and is mentioned above . Even the function name ā€œWrong_Solutionā€ suggests that it is wrong!

slow logic and the use of swap function is making it slower
and ur using brute forceā€¦think of some other logic

one mistake which I found is overflow in variable x .There may or may not be other mistakes.

(x/y)%z != (x%z)/(y%z)

1 Like

you need to do inverse to calc division modulo

another good editorial, which was written during the contest: combinatorics - Count the whistles - Mathematics Stack Exchange

Hey, @devuy11, the error in the pseudo code wrong_soltion
http://discuss.codechef.com/questions/47443/lcm-of-n-numbers-modulo-1097

This was not very obvious to me. (x.y)modm==((xmodm).y)modm modular arithmetic - Very simple question, but what is the proof that x.y mod m == ((x mod m).y) mod m? - Mathematics Stack Exchange