Find numbers that divide X and Y to produce the same remainder | Java program to find numbers that divide X and Y to produce the same remainder ; Function to find the required number as M ; Finding the maximum value among X and Y ; Loop to iterate through maximum value among X and Y . ; If the condition satisfies , then print the value of M ; Driver code
class GFG { static void printModulus ( int X , int Y ) { int n = Math . max ( X , Y ) ; for ( int i = 1 ; i <= n ; i ++ ) { if ( X % i == Y % i ) System . out . print ( i + " ▁ " ) ; } } public static void main ( String [ ] args ) { int X , Y ; X = 10 ; Y = 20 ; printModulus ( X , Y ) ; } }