CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2009
    Posts
    2

    finding MOD for each array element...

    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

  2. #2

    Re: finding MOD for each array element...

    Code:
    Q[1] mod P = Z
    Q[2] mod P = Z
    Q[3] mod P = Z
    implies
    Code:
    Q[2] - Q[1] mod P = 0
    Q[3] - Q[2] mod P = 0
    Q[1] - Q[3] mod P = 0
    so 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'.
    Last edited by pm_kirkham; April 1st, 2009 at 09:29 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured