Find numbers that divide X and Y to produce the same remainder | C ++ program to find numbers that divide X and Y to produce the same remainder ; Function to print all the possible values of M such that X % M = Y % M ; Finding the absolute difference of X and Y ; Iterating from 1 ; Loop to print all the factors of D ; If i is a factor of d , then print i ; If d / i is a factor of d , then print d / i ; Driver code
#include <iostream> NEW_LINE using namespace std ; void printModulus ( int X , int Y ) { int d = abs ( X - Y ) ; int i = 1 ; while ( i * i <= d ) { if ( d % i == 0 ) { cout << i << " ▁ " ; if ( d / i != i ) cout << d / i << " ▁ " ; } i ++ ; } } int main ( ) { int X = 10 ; int Y = 26 ; printModulus ( X , Y ) ; return 0 ; }