We are given an array A containing N elements (1<=N<=10^6). Now, we need to find all the distinct values (A[i]*A[j])%M where M is the product of two primes {both primes less than 600}. Clearly, it can be done in N^2 time but I am looking to solve this in time proportional to M (there can be atmost M distinct values).



