How can we calculate gcd of two big numbers in cpp? First of all, we will treat the two numbers as strings, then what is next? The problem attached has a utility of this gcd trick.

Need idea: I thought of finding all possible increasing and decreasing subsequences which is too slow. Can this be done efficiently? Also according to me there can be at max 1 element in common in both the subsequences. I am not getting how to use this information.