Distinct multiplicative modulo values in Array

Revision en1, by MSKB, 2017-01-10 22:37:56

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).

Tags number theory, modular arithmetic

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English MSKB 2017-01-11 10:31:51 303
en1 English MSKB 2017-01-10 22:37:56 365 Initial revision (published)