Minimum elements to be added in a range so that count of elements is divisible by K | PHP implementation of the approach ; Total elements in the range ; If total elements are already divisible by k ; Value that must be added to count in order to make it divisible by k ; Driver Program to test above function
< ? php function minimumMoves ( $ k , $ l , $ r ) { $ count = $ r - $ l + 1 ; if ( $ count % $ k == 0 ) return 0 ; return ( $ k - ( $ count % $ k ) ) ; } $ k = 3 ; $ l = 10 ; $ r = 10 ; echo minimumMoves ( $ k , $ l , $ r ) ; ? >