How to find X , at which (A + X * B) will be divided without remainder by C ?
For example: A = 17 , B = 199 , C = 11
(17 + X * 199) % 11 = 0
How to find X in the above example?
How to find X , at which (A + X * B) will be divided without remainder by C ?
For example: A = 17 , B = 199 , C = 11
(17 + X * 199) % 11 = 0
How to find X in the above example?
We consider everything on the module 11:
17 + X * 200 = 0 6 + X * 2 = 0 X * 2 = -6 X * 2 = 5 X = 5 / 2 The inverse element for 2 is 6 (since 2 * 6 = 1)
X = 5 * 6 X = 30 X = 8 The simplest option is brute force:
function solve(a, b, c) { for (var x=0; x<c; ++x) { if ((a + b*x) % c === 0) { return x; } } } console.log(solve(17, 199, 11)); Source: https://ru.stackoverflow.com/questions/613514/
All Articles