algorithmmathmodulo

Given a and b, find m such that a mod m = b mod m


I am trying to solve a algorithmic problem, which has a sub-part which asks you to find an integer m such that for given two integers a and b, we get a mod m = b mod m. mod is the modulo operation. How to approach this problem?


Solution

  •           a mod m = b mod m
    ==> (a - b) mod m = 0 
    ==>         (a-b) = k * m    for some integer k
    ==>     (a-b) / m = k
    

    So m can be any factor of a-b .