Mathematics hackerank

Can u please help me solving this

Yes this is actually a gcd problem. The amount of water in each jug is always a [linear combination] of a and b adn this linear combination has to be a multiple of gcd of a and b.
See this
If you still fail to understand this person solves the exact same problem

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.