Store the GCD of the length of the strings
INDENT gcd = GCD ( len ( a ) , len ( b ) ) NEW_LINE if a [ : gcd ] == b [ : gcd ] : NEW_LINE INDENT if a * ( len ( b ) // gcd ) == b * ( len ( a ) // gcd ) : NEW_LINE return a [ : gcd ] NEW_LINE DEDENT return - 1 NEW_LINE DEDENT