Modular GCD wrong Answer

I’m getting wrong answer in this question. Could anyone please tell me what’s wrong in this code?

Qustion : https://www.codechef.com/problems/GCDMOD

My code:https://www.codechef.com/viewsolution/37336081

Thanks in advance.

https://www.codechef.com/viewsolution/34024113
Your solution seems correct , don’t know where it goes wrong .

figured out bro , u have to use 128 bit int integer in your Binary exponentiation

I changes your code and it give AC : “https://www.codechef.com/viewsolution/37349401

1 Like

If u don’t wanna use 128 bit integer then u have to do modular multiplication (just like modular exponentiation)

https://www.geeksforgeeks.org/how-to-avoid-overflow-in-modular-multiplication/

1 Like