← Quiz: Number Theory for Coding: all 10 questions
Quiz: Number Theory for Coding · Question 10 of 10
Under modulo M = 10⁹ + 7, how do you correctly compute (a / b) mod M?
Under modulo M = 10⁹ + 7, how do you correctly compute (a / b) mod M?
- A.(a % M) / (b % M)
- B.a × b^(M − 2) mod M, using fast power for the inverse of b
- C.(a / b) % M with integer division
- D.a mod (b × M)
Answer & explanation
Correct answer: a × b^(M − 2) mod M, using fast power for the inverse of b
Fermat's little theorem gives the inverse of b when M is prime and b is not a multiple of M.
Can you get the rest right without peeking?
Take the timed Quiz: Number Theory for Coding quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →