• + 0 comments

    For both cases LCM(A) = GCD(B)+1 and GCD(B) - LCM(A) <<<< LCM(A) the result would be 0.

    For step-3 you need to run a loop from LCM upto GCD each time multiplying the LCM by 1,2,3.. so on. See the sudo code below.

    GCD%(LCM*i)==0, where i=1,2,3... until LCM*i<=GCM;
    

    If you think running a loop means brute forcing, then yes you have to use brute force. :)