• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 413
  • Last Modified:

equation with modulo, has a general solution?

a = (x*c) (mod b)
a, c, b are known positive naturals, can anyone tell how to calculate x?
0
ravenpl
Asked:
ravenpl
  • 3
  • 3
  • 3
  • +4
3 Solutions
 
d-glitchCommented:
There may not be a solution if b and c are not relatively prime.

   ==>  c =5   and   b = 10  yields solutions only for a = 0 [x = even]  and for  a = 5 [x = odd]
            There are no solutions for a = 1,2,3,4,6,7,8,9
0
 
aburrCommented:
The answer to your problem is straight forward but complicated to write. One has little trouble with the definition of division. But generalized modulo arithmetic is more complicated. In you r case
x = a/c          but the arithmetic is to be mod (b)
You need the definition of “mod”.  Mod is a function of two natural numbers which returns the remainder after the number m is subtracted from n so many times that the difference would change its sign if further subtractions were made. That is
n(mod(m) = m * frac(n/m)
 where the function frac(y) = y – [y] where the function [y] = the integer part of y.
Thus in your particular case
 X = b * (a/c – [a/c])
I know it is messy, but there are not simpler common standard symbols defined to simplify the notation. However you have your general answer.
0
 
sdstuberCommented:
assuming that was supposed to be written as

a = ((x*c) mod b)

or

a = (x*c) mod b


then x will be one of a subset of values of this form


x = (a + nb)/c   where n is 0,1,2,3...





0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
ravenplAuthor Commented:
sdstuber: I came with Your solution, but how to tell which n is OK?
aburr: assuming x=10 c=10 b=10 a eq 0; b * (a/c – [a/c]) render x=0 instead of 10?
0
 
aburrCommented:
I do not see how if a =  0 and c =10     x can be other than 0.
0
 
aburrCommented:
zeros are messy anyway
0
 
sdstuberCommented:
if X is an integer then I don't know how to determine valid "n" in general.

I made the assumption that X was supposed to be a natural like a,b,c

but, on second reading your requirement didn't specify that,
so,  as long as c is not 0, I think you can use


x = (a + nb)/c   where n is 0,1,2,3...

for all n

0
 
d-glitchCommented:
>>  I do not see how if a =  0 and c =10     x can be other than 0.


         If   a = 0   and   c =10   and   b = 100    x can be 10, 20, 30, ....
0
 
d-glitchCommented:

         If   a = 1   and   c = 9   and   b = 10      x can be 9, 19, 29, 39, ....
0
 
ravenplAuthor Commented:
OK, x is natural as well. Additionally c is prime if it matters(relatively to b). I think You should have now the whole picture. The function is quite simple hashing function(x as an input). What I need is to invert it.

ozo: that what I was afraid of, browsing the internet was leading there...

OK, let me try the iteration algo - looks simplest, yet lots of divisions.
0
 
TommySzalapskiCommented:
" assuming x=10 c=10 b=10 "
But if b and c are relatively prime then this can't happen.
Since they are all naturals, there are no 0s to worry about (remember, naturals are the whole numbers except 0).
So all the numbers are integers >= 1 and b is relatively prime to c.
So the solution is going to be x = y + n*b where n = 0,1,2,3,4,... and y is the minimum value of x that solves the problem.
0
 
TommySzalapskiCommented:
Of course if a >= b then there is no solution. Otherwise, there is one. If you look at the pattern, when you start x at 1 and keep increasing it, the values of a cycle through the numbers [0,b-1] in some fashion. Each number in that range appears once in the cycle and the same cycle repeats infinitely. So all you have left to do is find where you need to start (based on a).
I see no need to restrict a from being 0 but it doesn't really matter.
0
 
TommySzalapskiCommented:
Uh, there's no need to restrict x to the naturals either. As long as you are okay with negatives in modulo arithmetic (-1 mod 10 is 9).
So the solution will actually be in the form x = y + n*b where n is any integer and y is in the range of [0,b-1]
Here's the spreadsheet I've been playing with.
modulo.xls
0
 
phoffricCommented:
>> a = (x*c) (mod b)
If you are you talking about a Congruence relation, then a can be greater than b. For example, 38 == 14 mod 12 since 12 divides evenly into 38-14 (i.e., 24); or, alternatively, 38 mod 12 = remainer of 2 and 14 mod 12 = remainder of 2, so 38 == 14 mod 12.
0
 
ravenplAuthor Commented:
OK, I ended in iterating n in [0..c] range for x=(a + nb)/c - so far so good. Thanx for Your input.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

  • 3
  • 3
  • 3
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now