Modular GCD

https://paste.ubuntu.com/p/TTbRnkDQvr/

This is my solution for the above problem.I am not understanding why it is giving me WA. Can anyone please help?

In ans4 u made mistake as (a-b)%m gives error
If a-b<0 then u should add mod to it as well
U can do it like this
(((((a%MOD)-(b%MOD))%MOD)<0)?(int)(MOD+((a%MOD)-(b%MOD))%MOD):(int)(((a%MOD)-(b%MOD))%MOD))
Hope it helps :smile:

Its also giving Wrong answer.