1
$\begingroup$

My question is this. Given any two arbitrary positive integers a and b ∈ z , what is the minimum value of x such that:

b | (a * x) Find MINIMUM positive x such that product of a and x is divisible by b.

or Find minimum positive x such that:

ax ≡ 0 mod(b)

How do I solve this general equation to find min x for any arbitrary integers a & b?

For example:

ex1 a = 5, b = 14. Then x = 14 because 14 | 5x and 14 | 5 * 14

ex2 a = 14, b = 4, Then x = 2 because 4 | 14 * x and 4 | 14 * 2


Right now I'm using brute force program for solving this:

int x, limit = b;

// We know that Limit is b since b | a * b, we want to find x <= b

for(x = 1 ; x <= limit ; x++) {

    if((a * x) % b == 0)) {

        // exit the loop. solution found
        break;

    }
}

// prints minimum x and the value a*x for which b | a*x
print(x ,  a * x);

Please recommend an efficient mathematical solution. Thank you.

1 Answers 1

2

Find the greatest common divisor of $a,b$. Then evaluate $x=\frac b{\gcd(a,b)}$ You can prove this by considering the prime factorization of $b$. Then the equation reduces to $b | (a * \frac b{\gcd(a,b)})$ which is always true.

  • 0
    Your answer seems to be right but could you rewrite the variables in your answer please. I am interested in Finding 'X', not 'a'. We might find it confusing... Find 'x' such that 'b' divides product of 'a' and 'x'2017-02-16
  • 0
    I suggest, oath, that you take it as an exercise to correct the error in Ross' formula. Then you will know that you truly understand the solution.2017-02-16
  • 0
    I have made edits to this answer. The edit will make it easier for others to understand. I'll have to see if the edit gets accepted. For now, I'll mark @Ross's answer as accepted. Thank you for your help :)2017-02-16