Minimum product modulo N possible for any pair from a given range | Function to return the minimum possible value of ( i * j ) % N ; Stores the minimum remainder ; Iterate from L to R ; Iterate from L to R ; Prlet the minimum value of remainder ; If R - L >= N ; Driver Code
function minModulo ( L , R , N ) { if ( R - L < N ) { let ans = Number . MAX_VALUE ; for ( let i = L ; i <= R ; i ++ ) for ( let j = L ; j <= R ; j ++ ) if ( i != j ) ans = Math . min ( ans , ( i * j ) % N ) ; document . write ( ans ) ; } else { document . write ( 0 ) ; } } let L = 6 , R = 10 , N = 2019 ; minModulo ( L , R , N ) ;