Largest number by which given 3 numbers should be divided such that they leaves same remainder | C ++ program to find the largest numbers that leads to same remainder when divides given three sorted numbers ; __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 program
#include <bits/stdc++.h> NEW_LINE using namespace std ; int gcd ( int a , int b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } int sameRemainder ( int a , int b , int c ) { int a1 = ( b - a ) , b1 = ( c - b ) , c1 = ( c - a ) ; return gcd ( a1 , gcd ( b1 , c1 ) ) ; } int main ( ) { int a = 62 , b = 132 , c = 237 ; cout << sameRemainder ( a , b , c ) << endl ; return 0 ; }