We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Consider without modulo. a = bx, so to solve for x, x = a/b. Unfortunately we can't really divide under modulo, but we can write this equation as a * b^-1 = x or x is a times the multiplicative inverse of b.
Luckily we can find the mulitplicative inverse of b under modulo M (because M=10^9 + 7 is prime, so b | b < M is coprime to M). We can calculate it by (b^(M-2))%M
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Simple One
You are viewing a single comment's thread. Return to all comments →
Consider without modulo.
a = bx
, so to solve for x,x = a/b
. Unfortunately we can't really divide under modulo, but we can write this equation asa * b^-1 = x
or x is a times the multiplicative inverse of b.Luckily we can find the mulitplicative inverse of b under modulo M (because
M=10^9 + 7
is prime, sob | b < M
is coprime to M). We can calculate it by(b^(M-2))%M