Minimum product modulo N possible for any pair from a given range | C ++ 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
#include <bits/stdc++.h> NEW_LINE #define ll  long long NEW_LINE using namespace std ; void minModulo ( int L , int R , int N ) { if ( R - L < N ) { int ans = INT_MAX ; for ( ll i = L ; i <= R ; i ++ ) for ( ll j = L ; j <= R ; j ++ ) if ( i != j ) ans = min ( 0ll + ans , ( i * j ) % N ) ; cout << ans ; } else { cout << 0 ; } } int main ( ) { int L = 6 , R = 10 , N = 2019 ; minModulo ( L , R , N ) ; return 0 ; }