- Greedy, Mathematical, Modular Arithmetic

Minimum product modulo N possible for any pair from a given range

Minimum product modulo N possible for any pair from a given rangeGiven three integers L, R, and N, the task is to find the minimum possible value of (i * j) % N, where L ≤ i < j ≤ R.Examples:Input: L = 2020, R = 2040, N = 2019Output: 2Explanation: (2020 * 2021) % 2019 = 2Input: L = 15, R = 30, N = 15Output: 0Explanation: If one of the elements of the pair is 15, then the product of all such pairs will be divisible by 15. Therefore, the remainder will be 0, which is minimum possible.Approach: The given problem can be solved by finding the difference between L and R. If the difference is at least N, then the result will be 0. Otherwise, iterate over the range [L, R] and find the minimum product.Below is the implementation of the above approach:C++#include #define ll long longusing namespace std;void minModulo(int L, int R, int N){    if (R - L < N) {                int ans = INT_MAX;                for (ll i = L; i