Largest number by which given 3 numbers should be divided such that they leaves same remainder | __gcd function ; Function return number which divides these three number and leaves same remainder . ; We find the differences of all three pairs ; Return GCD of three differences . ; Driver code
function gcd ( a , b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } function sameRemainder ( a , b , c ) { var a1 = ( b - a ) , b1 = ( c - b ) , c1 = ( c - a ) ; return gcd ( a1 , gcd ( b1 , c1 ) ) ; } var a = 62 , b = 132 , c = 237 ; document . write ( sameRemainder ( a , b , c ) ) ;