I need to find an x value that satisfied:
x * a % m == b
x * c % n == d
Is there a smarter way to find the solution without iterating all the possibilites ?
function solve()
{
for (x=0;x<n*m-1;x++)
{
if((x * a % m == b) && (x * c % n == d))
return true;
}
return false;
}
As there is no direct correlation between these two equations (excepted the unkown X), I don't think that you can solve it in a really clever way. However, perhaps should you give a look to https://en.wikipedia.org/wiki/Chinese_remainder_theorem. This will not provide an answer to the topic itself, but could lead you to find some alternatives.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With