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.