Smallest number required to be added to M to make it divisible by N | Java program for the above approach ; Function to find the smallest number greater than or equal to N , that is divisible by k ; Function to find the smallest number required to be added to to M to make it divisible by N ; Stores the smallest multiple of N , greater than or equal to M ; Return the result ; Driver Code ; Given Input ; Function Call
class GFG { public static int findNum ( int N , int K ) { int rem = ( N + K ) % K ; if ( rem == 0 ) return N ; else return N + K - rem ; } public static int findSmallest ( int M , int N ) { int x = findNum ( M , N ) ; return x - M ; } public static void main ( String args [ ] ) { int M = 100 , N = 28 ; System . out . println ( findSmallest ( M , N ) ) ; } }