Minimum product modulo N possible for any pair from a given range | java program for the above approach ; 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 ; Print the minimum value of remainder ; If R - L >= N ; Driver Code
import java . io . * ; import java . lang . * ; import java . util . * ; public class GFG { static void minModulo ( int L , int R , int N ) { if ( R - L < N ) { int ans = Integer . MAX_VALUE ; for ( int i = L ; i <= R ; i ++ ) for ( int j = L ; j <= R ; j ++ ) if ( i != j ) ans = Math . min ( ans , ( i * j ) % N ) ; System . out . println ( ans ) ; } else { System . out . println ( 0 ) ; } } public static void main ( String [ ] args ) { int L = 6 , R = 10 , N = 2019 ; minModulo ( L , R , N ) ; } }