Click to See Complete Forum and Search --> : finding MOD for each array element...


linkin
April 1st, 2009, 12:45 AM
Guys, I’m looking for algorithmic solution for following task. Suppose we have array Q. let’s say Q is size of 3. I wanna find such P, that by MODing Q[i] mod P gives me Z. so basically

Q[1] mod P = Z
Q[2] mod P = Z
Q[3] mod P = Z

where Q[1] != Q[2] != Q[3]

In case if I take out any of Q[i] value, I will need to find P’ that does following

Q[1] mod P’ = W
Q[2] mod P’ = W

I’d appreciate any suggestion. If any of you has ever heard/done something like this, please let me know. It’d help a lot with one of my program.

Thanks in advance

pm_kirkham
April 1st, 2009, 09:25 AM
Q[1] mod P = Z
Q[2] mod P = Z
Q[3] mod P = ZimpliesQ[2] - Q[1] mod P = 0
Q[3] - Q[2] mod P = 0
Q[1] - Q[3] mod P = 0so P must be a factor of the difference of each of the values in Q, and one such value would be the greatest common divisor of the differences. If Z and W is known, you will have to find an appropriate factor of the gcd for which Q[1] mod P = Z and Q[1] mod P' = W, where you only consider the factors of Q[1]-Q[2] to find P'.